Skip to content

Fix IVF factory leak - #5612

Open
jbajic wants to merge 5 commits into
facebookresearch:mainfrom
jbajic:fix-ivf-factory-leak
Open

jbajic wants to merge 5 commits into
facebookresearch:mainfrom
jbajic:fix-ivf-factory-leak

Conversation

@jbajic

@jbajic jbajic commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

The alubsan leak happens when we have constructed the IVF,PQ3 with the broken quantization and the quantizer get released, and then the IVF construction throws and does not clean up the quantizer. The leak looks like this:

==88601==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x74b254616222 in operator new(unsigned long) ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:248
    #1 0x588a0cf4c4d7 in faiss::(anonymous namespace)::parse_coarse_quantizer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, faiss::MetricType, std::vector<std::unique_ptr<faiss::Index, std::default_delete<faiss::Index> >, std::allocator<std::unique_ptr<faiss::Index, std::default_delete<faiss::Index> > > >&, unsigned long&, bool&) [clone .isra.0] (/home/jbajic/Projects/faiss/ivf_quantizer_leak+0xac4d7) (BuildId: 45a0934ffe20c59ae7f414fa8f8845dcec85cc8b)
    #2 0x588a0cf55524 in faiss::(anonymous namespace)::index_factory_sub(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, faiss::MetricType, bool) (/home/jbajic/Projects/faiss/ivf_quantizer_leak+0xb5524) (BuildId: 45a0934ffe20c59ae7f414fa8f8845dcec85cc8b)
    #3 0x588a0cf5618a in faiss::index_factory(int, char const*, faiss::MetricType, bool) (/home/jbajic/Projects/faiss/ivf_quantizer_leak+0xb618a) (BuildId: 45a0934ffe20c59ae7f414fa8f8845dcec85cc8b)

SUMMARY: LeakSanitizer: 128 byte(s) leaked in 1 allocation(s).

And it can be reproduced with this example:

#include <faiss/impl/FaissException.h>
#include <faiss/index_factory.h>
#include <cstdio>

int main() {
    try {
        delete faiss::index_factory(8, "IVF4,PQ3");
    } catch (faiss::FaissException const& e) {
        fprintf(stderr, "threw: %s\n", e.what());
    }
}

and run with this: g++ -std=c++17 -g -fsanitize=leak -I. ivf_quantizer_leak.cpp build/faiss/libfaiss.a -llapack -lblas -fopenmp -o ivf_quantizer_leak && ./ivf_quantizer_leak

@meta-cla meta-cla Bot added the CLA Signed label Sep 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant