From: Michal Privoznik Date: Mon, 7 Apr 2014 15:29:18 +0000 (+0200) Subject: bhyveConnectGetCapabilities: Fix double caps unref X-Git-Tag: v1.2.4-rc1~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23419a62c28a3936859c14d5cc877ae429251f23;p=thirdparty%2Flibvirt.git bhyveConnectGetCapabilities: Fix double caps unref At the beginning of the function we gain a reference to the driver capabilities. Then, we call format function (*) which if failed, unref over caps is called. Then, at the end another unref occurs. * - Moreover, the format was not called over gained caps, but over privconn->caps directly which is not allowed anymore. Signed-off-by: Michal Privoznik --- diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 6ef9d98656..a5b349a862 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -135,22 +135,24 @@ bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; virCapsPtr caps; - char *xml; + char *xml = NULL; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; - caps = bhyveDriverGetCapabilities(privconn); - if (!caps) + if (!(caps = bhyveDriverGetCapabilities(privconn))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to get Capabilities")); + goto cleanup; + } - if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) { - virObjectUnref(caps); + if (!(xml = virCapabilitiesFormatXML(caps))) { virReportOOMError(); + goto cleanup; } - virObjectUnref(caps); + cleanup: + virObjectUnref(caps); return xml; }