qemu: don't leak in qemuGetDHCPInterfaces when failing to alloc

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>
This commit is contained in:
Chen Hanxiao 2018-02-11 11:07:10 +08:00 committed by Michal Privoznik
parent a90a1bf9e1
commit 60a95e5242
2 changed files with 5 additions and 7 deletions

View 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:

View 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: