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.93~122^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=60b019f69aa0e39d276c669698c92fc890599f50;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 --- diff --git a/src/pybind/rados.py b/src/pybind/rados.py index b50b67ce392c..05c49dbb91e5 100644 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -998,6 +998,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): @@ -1009,9 +1011,6 @@ class Ioctx(object): self.nspace = "" 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): @@ -1064,9 +1063,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)))