summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2018-04-30 09:26:45 +0200
committerJason Wang <jasowang@redhat.com>2018-05-14 15:47:12 +0800
commit9d94619189d899b2b40e9dfaa0ede64c8b81e5ab (patch)
tree2d0a9cf7764ad89fb07c3fa4ed49fc409654d6a0 /net
parentc74e62ee3e2dc2955e07d004c71badecb68a84eb (diff)
net: Fix memory leak in net_param_nic()
The early exits in case of errors leak the memory allocated for nd_id. Fix it by using a "goto out" to the cleanup at the end of the function instead. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net')
-rw-r--r--net/net.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/net/net.c b/net/net.c
index 29f83983e5..65457b7976 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1502,11 +1502,12 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)
g_free(mac);
if (ret) {
error_setg(errp, "invalid syntax for ethernet address");
- return -1;
+ goto out;
}
if (is_multicast_ether_addr(ni->macaddr.a)) {
error_setg(errp, "NIC cannot have multicast MAC address");
- return -1;
+ ret = -1;
+ goto out;
}
}
qemu_macaddr_default_if_unset(&ni->macaddr);
@@ -1518,6 +1519,7 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)
nb_nics++;
}
+out:
g_free(nd_id);
return ret;
}