Skip to content

Commit

Permalink
Fix memory leak on test code (#1776)
Browse files Browse the repository at this point in the history
Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 authored Jun 28, 2024
1 parent fe14b21 commit 4befe2b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions jni/tests/faiss_wrapper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,13 @@ TEST(FaissCreateHnswSQfp16IndexTest, BasicAssertions) {
// Define the data
faiss::idx_t numIds = 200;
std::vector<faiss::idx_t> ids;
auto *vectors = new std::vector<float>();
std::vector<float> vectors;
int dim = 2;
vectors->reserve(dim * numIds);
vectors.reserve(dim * numIds);
for (int64_t i = 0; i < numIds; ++i) {
ids.push_back(i);
for (int j = 0; j < dim; ++j) {
vectors->push_back(test_util::RandomFloat(-500.0, 500.0));
vectors.push_back(test_util::RandomFloat(-500.0, 500.0));
}
}

Expand All @@ -655,14 +655,14 @@ TEST(FaissCreateHnswSQfp16IndexTest, BasicAssertions) {
EXPECT_CALL(mockJNIUtil,
GetJavaObjectArrayLength(
jniEnv, reinterpret_cast<jobjectArray>(&vectors)))
.WillRepeatedly(Return(vectors->size()));
.WillRepeatedly(Return(vectors.size()));

// Create the index
std::unique_ptr<FaissMethods> faissMethods(new FaissMethods());
knn_jni::faiss_wrapper::IndexService IndexService(std::move(faissMethods));
knn_jni::faiss_wrapper::CreateIndex(
&mockJNIUtil, jniEnv, reinterpret_cast<jintArray>(&ids),
(jlong)vectors, dim, (jstring)&indexPath,
(jlong)&vectors, dim, (jstring)&indexPath,
(jobject)&parametersMap, &IndexService);

// Make sure index can be loaded
Expand Down

0 comments on commit 4befe2b

Please sign in to comment.