Commit 9d946191 authored by Thomas Huth's avatar Thomas Huth Committed by Jason Wang
Browse files

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: default avatarPeter Maydell <peter.maydell@linaro.org>
Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
parent c74e62ee
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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;
}