From: Ali Maredia Date: Thu, 15 Sep 2022 18:43:37 +0000 (-0400) Subject: common: add destructor to intrusive_lru X-Git-Tag: v16.2.15~32^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=65b22e8cb6180fe30865b8883eb3d15f29d7d1fa;p=ceph.git common: add destructor to intrusive_lru values created during inserts that are unreferenced are not deleted because evict() does not delete values unless set.size() > lru_target_size. For example, this condition is not met if the number of entries in the intrusive_lru are less than or equal to lru_target_size at the time of the intrusive_lru's destruction. Memory leaks due to the above scenario can be reproduced if this commit is removed and unittest_intrusive_lru is run under valgrind. ex: valgrind --tool=memcheck --leak-check=yes ./bin/unittest_intrusive_lru Signed-off-by: Ali Maredia (cherry picked from commit abd84ad770ffe10771aeae060514a42e76150569) --- diff --git a/src/common/intrusive_lru.h b/src/common/intrusive_lru.h index 422c24a14fb6..2837f67984b3 100644 --- a/src/common/intrusive_lru.h +++ b/src/common/intrusive_lru.h @@ -166,6 +166,10 @@ public: evict(); } + ~intrusive_lru() { + set_target_size(0); + } + friend void intrusive_ptr_add_ref<>(intrusive_lru_base *); friend void intrusive_ptr_release<>(intrusive_lru_base *); };