fix minor memory leak when querying by IVF_SQ8H (#4758)

* fix minor memory leak when querying by IVF_SQ8H

Signed-off-by: shengjun.li <shengjun.li@zilliz.com>

* fix mismatch malloc/free new/delete

Signed-off-by: shengjun.li <shengjun.li@zilliz.com>
pull/4760/head
shengjun.li 2021-03-01 19:57:53 +08:00 committed by GitHub
parent dbdf120b7b
commit 5ad002effa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 15 deletions

View File

@ -6,6 +6,7 @@ Please mark all change in change log and use the issue from GitHub
## Bug
- \#4739 Fix mishards probe test problem
- \#4749 Fix minor memory leak when building IVF_SQ8 on GPU
- \#4757 Fix minor memory leak when querying by IVF_SQ8H
## Feature
- \#3977 Support logging to stdout

View File

@ -138,12 +138,12 @@ IVFSQHybrid::LoadData(const FaissIVFQuantizerPtr& quantizer_ptr, const Config& c
if (ivf_quantizer == nullptr)
KNOWHERE_THROW_MSG("quantizer type not faissivfquantizer");
auto index_composition = new faiss::IndexComposition;
index_composition->index = index_.get();
index_composition->quantizer = ivf_quantizer->quantizer;
index_composition->mode = 2; // only 2
faiss::IndexComposition index_composition;
index_composition.index = index_.get();
index_composition.quantizer = ivf_quantizer->quantizer;
index_composition.mode = 2; // only copy data
auto gpu_index = faiss::gpu::index_cpu_to_gpu(res->faiss_res.get(), gpu_id, index_composition, &option);
auto gpu_index = faiss::gpu::index_cpu_to_gpu(res->faiss_res.get(), gpu_id, &index_composition, &option);
std::shared_ptr<faiss::Index> new_idx;
new_idx.reset(gpu_index);
auto sq_idx = std::make_shared<IVFSQHybrid>(new_idx, gpu_id, res);
@ -162,17 +162,17 @@ IVFSQHybrid::LoadQuantizer(const Config& config) {
faiss::gpu::GpuClonerOptions option;
option.allInGpu = true;
auto index_composition = new faiss::IndexComposition;
index_composition->index = index_.get();
index_composition->quantizer = nullptr;
index_composition->mode = 1; // only 1
faiss::IndexComposition index_composition;
index_composition.index = index_.get();
index_composition.quantizer = nullptr;
index_composition.mode = 1; // only copy quantizer
auto gpu_index = faiss::gpu::index_cpu_to_gpu(res->faiss_res.get(), gpu_id, index_composition, &option);
auto gpu_index = faiss::gpu::index_cpu_to_gpu(res->faiss_res.get(), gpu_id, &index_composition, &option);
delete gpu_index;
auto q = std::make_shared<FaissIVFQuantizer>();
auto& q_ptr = index_composition->quantizer;
auto q_ptr = index_composition.quantizer;
q->size = q_ptr->d * q_ptr->getNumVecs() * sizeof(float);
q->quantizer = q_ptr;
q->gpu_id = gpu_id;

View File

@ -42,14 +42,14 @@ class GPURESTEST : public DataGen, public TestGpuIndexBase {
k = K;
elems = nq * k;
ids = (int64_t*)malloc(sizeof(int64_t) * elems);
dis = (float*)malloc(sizeof(float) * elems);
ids = new int64_t[elems];
dis = new float[elems];
}
void
TearDown() override {
delete ids;
delete dis;
delete[] ids;
delete[] dis;
TestGpuIndexBase::TearDown();
}