]> git.ipfire.org Git - pakfire.git/blobdiff - src/_pakfire/ctx.c
python: ctx: Cleanup code that dereferences the logging function
[pakfire.git] / 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);
 }