]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
mgr/TTLCache: fix PyObject* lifetime management and cleanup logic
authorNitzan Mordechai <nmordech@redhat.com>
Tue, 26 Aug 2025 14:30:12 +0000 (14:30 +0000)
committerNitzanMordhai <nmordech@ibm.com>
Thu, 5 Mar 2026 06:53:36 +0000 (06:53 +0000)
commit610ed6a214ade36195aed52b1d0e64a962a40ee0
tree613f841480ce75697508aba2bc9c60a8d9dafdb9
parent7f47def55118bcd7ad36c05c06a669ed1f4587b2
mgr/TTLCache: fix PyObject* lifetime management and cleanup logic

Fix incorrect reference counting and memory retention behavior in TTLCache
when storing PyObject* values.
Previously, TTLCache::insert did not increment the reference count,
and `erase` / `clear` did not correctly decref the values, leading
to use-after-free or leaks depending on usage.

Changes:
- Move Py_INCREF from cacheable_get_python() to TTLCache::insert()
- Add `TTLCache::clear()` method for proper memory cleanup
- Ensure TTLCache::get() returns a new reference
- Fix misuse of std::move on c_str() in PyJSONFormatter

These changes prevent both memory leaks and use-after-free errors when
mgr modules use cached Python objects logic.

Fixes: https://tracker.ceph.com/issues/68989
Signed-off-by: Nitzan Mordechai <nmordech@redhat.com>
(cherry picked from commit 7fadf6a8d464456668550e1f85c6c5a86f94bb49)
src/mgr/ActivePyModules.cc
src/mgr/PyFormatter.cc
src/mgr/TTLCache.cc
src/mgr/TTLCache.h