]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: Correctly ref and close the virCHMonitor in virCHMonitorNew
authorWilliam Douglas <william.douglas@intel.com>
Fri, 1 Oct 2021 18:12:34 +0000 (11:12 -0700)
committerLaine Stump <laine@redhat.com>
Tue, 5 Oct 2021 04:07:23 +0000 (00:07 -0400)
In virCHMontiorNew the monitor object was referenced an additional
time incorrectly preventing it from being disposed of, and wasn't
always closed properly on failure.

Signed-off-by: William Douglas <william.douglas@intel.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/ch/ch_monitor.c

index a1430f0e65a5f8270a845568d13f7ac4b1f81fc3..807989579b50bd1fecac9434cddcba007fc3afc9 100644 (file)
@@ -468,7 +468,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
     if (!vm->def) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("VM is not defined"));
-        return NULL;
+        goto cleanup;
     }
 
     /* prepare to launch Cloud-Hypervisor socket */
@@ -502,12 +502,13 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
     mon->handle = curl_easy_init();
 
     /* now has its own reference */
-    virObjectRef(mon);
     mon->vm = virObjectRef(vm);
 
     ret = mon;
+    mon = NULL;
 
  cleanup:
+    virCHMonitorClose(mon);
     virCommandFree(cmd);
     return ret;
 }