Skip to content

Commit 8f5adc8

Browse files
3tothe6facebook-github-bot
authored andcommitted
Fix potential memory leak in InvertedLists default implementation (#2412)
Summary: According to `InvertedLists` API conventions, pointers returned from `get_ids` must be released by `release_ids`, which is violated by `get_single_id`. Note that all subclasses of `InvertedLists` which overwrite `release_ids` also overwrite `get_single_id`, the code change has no actual runtime impact with respect to existing code. However, if someone wants to implement his or her `InvertedLists` subclass and chooses not to overwrite `get_single_id`, this code change will help him or her to avoid potential memory leak. Pull Request resolved: #2412 Reviewed By: alexanderguzhva Differential Revision: D39167152 Pulled By: mdouze fbshipit-source-id: d2daef801a4c375d5e2c80ea1fdf259bf31e4b3d
1 parent fc13d84 commit 8f5adc8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

faiss/invlists/InvertedLists.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ InvertedLists::~InvertedLists() {}
2828
InvertedLists::idx_t InvertedLists::get_single_id(size_t list_no, size_t offset)
2929
const {
3030
assert(offset < list_size(list_no));
31-
return get_ids(list_no)[offset];
31+
const idx_t* ids = get_ids(list_no);
32+
idx_t id = ids[offset];
33+
release_ids(list_no, ids);
34+
return id;
3235
}
3336

3437
void InvertedLists::release_codes(size_t, const uint8_t*) const {}

0 commit comments

Comments
 (0)