提交 60a95e52 编写于 作者: C Chen Hanxiao 提交者: Michal Privoznik

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: NChen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 a90a1bf9
...@@ -2190,8 +2190,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon, ...@@ -2190,8 +2190,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
iface->naddrs = addrs_count; iface->naddrs = addrs_count;
} }
*ifaces = ifaces_ret; VIR_STEAL_PTR(*ifaces, ifaces_ret);
ifaces_ret = NULL;
ret = ifaces_count; ret = ifaces_count;
cleanup: cleanup:
......
...@@ -20569,10 +20569,10 @@ qemuGetDHCPInterfaces(virDomainPtr dom, ...@@ -20569,10 +20569,10 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
goto error; goto error;
if (VIR_STRDUP(iface->name, vm->def->nets[i]->ifname) < 0) if (VIR_STRDUP(iface->name, vm->def->nets[i]->ifname) < 0)
goto cleanup; goto error;
if (VIR_STRDUP(iface->hwaddr, macaddr) < 0) if (VIR_STRDUP(iface->hwaddr, macaddr) < 0)
goto cleanup; goto error;
} }
for (j = 0; j < n_leases; j++) { for (j = 0; j < n_leases; j++) {
...@@ -20580,7 +20580,7 @@ qemuGetDHCPInterfaces(virDomainPtr dom, ...@@ -20580,7 +20580,7 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
virDomainIPAddressPtr ip_addr = &iface->addrs[j]; virDomainIPAddressPtr ip_addr = &iface->addrs[j];
if (VIR_STRDUP(ip_addr->addr, lease->ipaddr) < 0) if (VIR_STRDUP(ip_addr->addr, lease->ipaddr) < 0)
goto cleanup; goto error;
ip_addr->type = lease->type; ip_addr->type = lease->type;
ip_addr->prefix = lease->prefix; ip_addr->prefix = lease->prefix;
...@@ -20592,8 +20592,7 @@ qemuGetDHCPInterfaces(virDomainPtr dom, ...@@ -20592,8 +20592,7 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
VIR_FREE(leases); VIR_FREE(leases);
} }
*ifaces = ifaces_ret; VIR_STEAL_PTR(*ifaces, ifaces_ret);
ifaces_ret = NULL;
rv = ifaces_count; rv = ifaces_count;
cleanup: cleanup:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册