]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuBuildHostNetStr: Don't leak buffer
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 11 Sep 2017 08:48:33 +0000 (10:48 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 12 Sep 2017 11:41:31 +0000 (13:41 +0200)
If there was an error when constructing the buffer, NULL is
returned. The buffer is never freed though.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_command.c

index e57a3278e09b9feaa680c26eb16fdc6fa5118041..d553df57f496cade202a3fb006e94e6083103adf 100644 (file)
@@ -3805,13 +3805,13 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
     virDomainNetType netType = virDomainNetGetActualType(net);
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     size_t i;
+    char *ret = NULL;
 
     if (net->script && netType != VIR_DOMAIN_NET_TYPE_ETHERNET) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("scripts are not supported on interfaces of type %s"),
                        virDomainNetTypeToString(netType));
-        virObjectUnref(cfg);
-        return NULL;
+        goto cleanup;
     }
 
     switch (netType) {
@@ -3919,13 +3919,16 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
             virBufferAsprintf(&buf, "sndbuf=%lu,", net->tune.sndbuf);
     }
 
-    virObjectUnref(cfg);
 
     virBufferTrim(&buf, ",", -1);
     if (virBufferCheckError(&buf) < 0)
-        return NULL;
+        goto cleanup;
 
-    return virBufferContentAndReset(&buf);
+    ret = virBufferContentAndReset(&buf);
+ cleanup:
+    virBufferFreeAndReset(&buf);
+    virObjectUnref(cfg);
+    return ret;
 }