From a04cfaa179248f4483d4201acb05f02f75130047 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 10 Jun 2015 15:40:34 +0200 Subject: [PATCH] pyldb: DECREF old debug function when resetting it Signed-off-by: Petr Viktorin Reviewed-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher --- lib/ldb/pyldb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index 66369cb57bf..5010f80c7a4 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -837,6 +837,8 @@ static void py_ldb_debug(void *context, enum ldb_debug_level level, const char * PyObject_CallFunction(fn, discard_const_p(char, "(i,O)"), level, PyString_FromFormatV(fmt, ap)); } +static PyObject *py_ldb_debug_func; + static PyObject *py_ldb_set_debug(PyObject *self, PyObject *args) { PyObject *cb; @@ -845,8 +847,13 @@ static PyObject *py_ldb_set_debug(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "O", &cb)) return NULL; + if (py_ldb_debug_func != NULL) { + Py_DECREF(py_ldb_debug_func); + } + Py_INCREF(cb); - /* FIXME: Where do we DECREF cb ? */ + /* FIXME: DECREF cb when exiting program */ + py_ldb_debug_func = cb; ldb_ctx = pyldb_Ldb_AsLdbContext(self); PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ldb_set_debug(ldb_ctx, py_ldb_debug, cb), -- 2.11.4.GIT