]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
python: ctx: Cleanup code that dereferences the logging function
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 25 Jan 2024 16:43:47 +0000 (16:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 25 Jan 2024 16:43:47 +0000 (16:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/ctx.c

index e6729be4dd6ccc9546bdcf915ca28e208b52842c..1ec16afbb3dd59d588cc5021dd04f196817ac1ff 100644 (file)
@@ -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);
 }