From: Billy Olsen Date: Mon, 2 Feb 2015 23:24:59 +0000 (-0700) Subject: Fix memory leak in python rados bindings X-Git-Tag: v0.80.10~68^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3bab47054dc77b9a00d3f47fa73f458ede7d4ab4;p=ceph.git Fix memory leak in python rados bindings A circular reference was inadvertently created when using the CFUNCTYPE binding for callbacks for the asynchronous i/o callbacks. This commit refactors the usage of the callbacks such that the Ioctx object does not have a class reference to the callbacks. Fixes: #10723 Backport: giant, firefly, dumpling Signed-off-by: Billy Olsen Reviewed-by: Dan Mick Reviewed-by: Josh Durgin (cherry picked from commit 60b019f69aa0e39d276c669698c92fc890599f50) --- diff --git a/src/pybind/rados.py b/src/pybind/rados.py index ec689193bc4..d7a8ba22680 100644 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -879,6 +879,8 @@ class Completion(object): run_in_thread(self.ioctx.librados.rados_aio_release, (self.rados_comp,)) +RADOS_CB = CFUNCTYPE(c_int, c_void_p, c_void_p) + class Ioctx(object): """rados.Ioctx object""" def __init__(self, name, librados, io): @@ -889,9 +891,6 @@ class Ioctx(object): self.locator_key = "" self.safe_cbs = {} self.complete_cbs = {} - RADOS_CB = CFUNCTYPE(c_int, c_void_p, c_void_p) - self.__aio_safe_cb_c = RADOS_CB(self.__aio_safe_cb) - self.__aio_complete_cb_c = RADOS_CB(self.__aio_complete_cb) self.lock = threading.Lock() def __enter__(self): @@ -944,9 +943,9 @@ class Ioctx(object): complete_cb = None safe_cb = None if oncomplete: - complete_cb = self.__aio_complete_cb_c + complete_cb = RADOS_CB(self.__aio_complete_cb) if onsafe: - safe_cb = self.__aio_safe_cb_c + safe_cb = RADOS_CB(self.__aio_safe_cb) ret = run_in_thread(self.librados.rados_aio_create_completion, (c_void_p(0), complete_cb, safe_cb, byref(completion)))