From: Michael Tremer Date: Thu, 25 Jan 2024 16:43:47 +0000 (+0000) Subject: python: ctx: Cleanup code that dereferences the logging function X-Git-Tag: 0.9.30~1247 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5273b4c6013ca5ab4750718790681a7550877c9;p=pakfire.git python: ctx: Cleanup code that dereferences the logging function Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/ctx.c b/src/_pakfire/ctx.c index e6729be4d..1ec16afbb 100644 --- a/src/_pakfire/ctx.c +++ b/src/_pakfire/ctx.c @@ -122,8 +122,7 @@ static void Ctx___set_logger(CtxObject* self, PyObject* logger) { Py_XINCREF(self->logger); // Set the logger - if (self->ctx) - pakfire_ctx_set_log_callback(self->ctx, Ctx_log_callback, self->logger); + pakfire_ctx_set_log_callback(self->ctx, Ctx_log_callback, self->logger); } static int Ctx_setup_logging(CtxObject* self) { @@ -184,11 +183,14 @@ static int Ctx_init(CtxObject* self, PyObject* args, PyObject* kwargs) { } static void Ctx_dealloc(CtxObject* self) { - // Reset the logger - Ctx___set_logger(self, NULL); + if (self->ctx) { + // Reset the logger + pakfire_ctx_set_log_callback(self->ctx, NULL, NULL); - if (self->ctx) pakfire_ctx_unref(self->ctx); + } + + Py_XDECREF(self->logger); Py_TYPE(self)->tp_free((PyObject *)self); }