]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
net: Fix memory leak in net_param_nic()
authorThomas Huth <thuth@redhat.com>
Mon, 30 Apr 2018 07:26:45 +0000 (09:26 +0200)
committerJason Wang <jasowang@redhat.com>
Mon, 14 May 2018 07:47:12 +0000 (15:47 +0800)
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>
net/net.c

index 29f83983e55d6b0e029ea1e6ae5c908b7755a740..65457b7976dc5536d63315d727e7e98986ed6bb7 100644 (file)
--- 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;
 }