[libvirt] [PATCH] Fix incorrect reference counting logic in qemu monitor open

Daniel P. Berrange berrange at redhat.com
Fri Nov 13 11:45:10 UTC 2009

The QEMU monitor open method would not take a reference on
the virDomainObjPtr until it had successfully opened the
monitor. The cleanup code upon failure to open though would
call qemuMonitorClose() which would in turn decrement the
reference count. This caused the virDoaminObjPtr to be mistakenly
freed and then the whole driver crashes

* src/qemu/qemu_monitor.c: Fix reference counting in
 src/qemu/qemu_monitor.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 2357734..f0ef81b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -456,6 +456,7 @@ qemuMonitorOpen(virDomainObjPtr vm,
     mon->vm = vm;
     mon->eofCB = eofCB;
+    virDomainObjRef(vm);
     switch (vm->monitor_chr->type) {
@@ -499,8 +500,6 @@ qemuMonitorOpen(virDomainObjPtr vm,
         goto cleanup;
-    virDomainObjRef(vm);
     VIR_DEBUG("New mon %p fd =%d watch=%d", mon, mon->fd, mon->watch);

More information about the libvir-list mailing list