]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: don't leak in qemuGetDHCPInterfaces when failing to alloc
authorChen Hanxiao <chenhanxiao@gmail.com>
Sun, 11 Feb 2018 03:07:10 +0000 (11:07 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 12 Feb 2018 06:57:26 +0000 (07:57 +0100)
We forgot to free alloced mem when failed to
dup ifname or macaddr.

Also use VIR_STEAL_PTR to simplify codes.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_agent.c
src/qemu/qemu_driver.c

index 5d125c4138c7627cba5c88c2bffa3d5e02b78381..0f36054a6160e24fe26e7e0138194afc6c14d071 100644 (file)
@@ -2190,8 +2190,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
         iface->naddrs = addrs_count;
     }
 
-    *ifaces = ifaces_ret;
-    ifaces_ret = NULL;
+    VIR_STEAL_PTR(*ifaces, ifaces_ret);
     ret = ifaces_count;
 
  cleanup:
index 978ecd4e073e83b34473ce10cc92714672371c93..bbce5bd81bd8ed655fcc3cd8a0511c63b4012fc6 100644 (file)
@@ -20569,10 +20569,10 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
                 goto error;
 
             if (VIR_STRDUP(iface->name, vm->def->nets[i]->ifname) < 0)
-                goto cleanup;
+                goto error;
 
             if (VIR_STRDUP(iface->hwaddr, macaddr) < 0)
-                goto cleanup;
+                goto error;
         }
 
         for (j = 0; j < n_leases; j++) {
@@ -20580,7 +20580,7 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
             virDomainIPAddressPtr ip_addr = &iface->addrs[j];
 
             if (VIR_STRDUP(ip_addr->addr, lease->ipaddr) < 0)
-                goto cleanup;
+                goto error;
 
             ip_addr->type = lease->type;
             ip_addr->prefix = lease->prefix;
@@ -20592,8 +20592,7 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
         VIR_FREE(leases);
     }
 
-    *ifaces = ifaces_ret;
-    ifaces_ret = NULL;
+    VIR_STEAL_PTR(*ifaces, ifaces_ret);
     rv = ifaces_count;
 
  cleanup: