[libvirt] [PATCH] qemu: don't leak in qemuGetDHCPInterfaces when failing to alloc
Michal Privoznik
mprivozn at redhat.com
Mon Feb 12 07:00:12 UTC 2018
On 02/11/2018 04:07 AM, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao at gmail.com>
>
> 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 at gmail.com>
> ---
> src/qemu/qemu_agent.c | 3 +--
> src/qemu/qemu_driver.c | 7 +++----
> 2 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index 5d125c413..0f36054a6 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -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:
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 978ecd4e0..60cdd237a 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -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++) {
Almost. There's another 'goto cleanup' in this for() loop. I'm fixing
that too. ACKing and pushing.
Michal
More information about the libvir-list
mailing list