From 60b019f69aa0e39d276c669698c92fc890599f50 Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Mon, 2 Feb 2015 16:24:59 -0700 Subject: [PATCH] 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 --- src/pybind/rados.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pybind/rados.py b/src/pybind/rados.py index b50b67ce392c0..05c49dbb91e5c 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))) -- 2.39.5