]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: Fix refcounting in virCHEventHandlerLoop() and virCHStartEventHandler()
authorKirill Shchetiniuk <kshcheti@redhat.com>
Fri, 14 Mar 2025 11:51:19 +0000 (12:51 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 17 Mar 2025 13:11:15 +0000 (14:11 +0100)
When event handler thread is created inside of
virCHStartEventHandler() the monitor object is refed because the thread
(virCHEventHandlerLoop()) that's created in the very next step
uses it. But right after that, the monitor object is unrefed,
which is wrong because it takes away the reference which was
handed over to the thread. The monitor must be unrefed inside the
thread, when no longer needed.

And while at it, move the unref call of the domain object after
the debug print which obviously accesses the domain definition.

Signed-off-by: Kirill Shchetiniuk <kshcheti@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/ch/ch_events.c

index 1cce30836a29a0558e68daea025626e6506730d7..2dd3e7ecc207c034f6e551e32d6fc190f344c8e4 100644 (file)
@@ -287,8 +287,9 @@ virCHEventHandlerLoop(void *data)
     }
 
     g_clear_pointer(&mon->event_buffer.buffer, g_free);
-    virObjectUnref(vm);
     VIR_DEBUG("%s: Event handler loop thread exiting", vm->def->name);
+    virObjectUnref(vm);
+    virObjectUnref(mon);
     return;
 }
 
@@ -308,7 +309,6 @@ virCHStartEventHandler(virCHMonitor *mon)
         virObjectUnref(mon);
         return -1;
     }
-    virObjectUnref(mon);
 
     g_atomic_int_set(&mon->event_handler_stop, 0);
     return 0;