From 9640d9fe5153540441ce43434aee2d2fd068601c Mon Sep 17 00:00:00 2001 From: deepkaran Date: Fri, 1 Nov 2024 10:09:17 -0700 Subject: [PATCH] MB-61093 Fix memory leak for SQDistanceComputer * Use unique_ptr to manage SQDistanceComputer lifecycle. --- faiss/IndexScalarQuantizer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/faiss/IndexScalarQuantizer.cpp b/faiss/IndexScalarQuantizer.cpp index ffba2c6405..eefdf10a21 100644 --- a/faiss/IndexScalarQuantizer.cpp +++ b/faiss/IndexScalarQuantizer.cpp @@ -289,8 +289,9 @@ void IndexIVFScalarQuantizer::compute_distance_to_codes_for_list( const uint8_t* codes, float* dists) const { - ScalarQuantizer::SQDistanceComputer* dc = - sq.get_distance_computer(metric_type); + std::unique_ptr dc( + sq.get_distance_computer(metric_type)); + dc->code_size = sq.code_size; if (by_residual) {