Skip to content

Commit c288607

Browse files
wenxin0319facebook-github-bot
authored andcommitted
Add Virtual Destructor to FlatIndex Class (#4381)
Summary: Pull Request resolved: #4381 This change introduces a virtual destructor to the FlatIndex class to ensure proper cleanup of derived class objects when they are deleted through a base class pointer. This modification addresses the compiler warning about deleting objects with virtual functions but non-virtual destructors, thereby preventing potential resource leaks and undefined behavior. Original Errors: ``` Remote action, reproduce with: `frecli cas download-action 5c1f300e23c7f3a3c0ac1e5644473bfc3940abade7d8c1496bf2adcb5b1c8181:145` Stdout: <empty> Stderr: fbcode/third-party-buck/platform010/build/libgcc/include/c++/trunk/bits/unique_ptr.h:85:1: error: delete called on non-final 'faiss::gpu::FlatIndex' that has virtual functions but non-virtual destructor [-Werror,-Wdelete-non-abstract-non-virtual-dtor] 85 | delete __ptr; | ^ fbcode/third-party-buck/platform010/build/libgcc/include/c++/trunk/bits/unique_ptr.h:361:1: note: in instantiation of member function 'std::default_delete<faiss::gpu::FlatIndex>::operator()' requested here 361 | get_deleter()(std::move(__ptr)); } | ^ fbcode/faiss/gpu/GpuIndexFlat.cu:28:15: note: in instantiation of member function 'std::unique_ptr<faiss::gpu::FlatIndex>::~unique_ptr' requested here 28 | GpuIndexFlat::GpuIndexFlat(GpuResourcesProvider * | ^ 1 error generated. ``` Reviewed By: zhuhan0 Differential Revision: D76303668 fbshipit-source-id: 27965d6dc4fd03366d599be8a3760be1df668d5b
1 parent 0e18107 commit c288607

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

faiss/gpu/impl/FlatIndex.cuh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class FlatIndex {
9797
/// Free all storage
9898
void reset();
9999

100+
// Add a virtual destructor to avoid warnings
101+
virtual ~FlatIndex() {}
102+
100103
protected:
101104
/// Collection of GPU resources that we use
102105
GpuResources* resources_;

0 commit comments

Comments
 (0)