qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic()
Date: Wed, 2 May 2018 10:20:21 +0800	[thread overview]
Message-ID: <344c0609-0fed-2fe1-1415-24b09e7731f9@redhat.com> (raw)
In-Reply-To: <1525073205-22394-1-git-send-email-thuth@redhat.com>



On 2018年04月30日 15:26, Thomas Huth wrote:
> 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.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   net/net.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/net/net.c b/net/net.c
> index 29f8398..65457b7 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;
>   }

Applied, thanks.

      parent reply	other threads:[~2018-05-02  2:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30  7:26 [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic() Thomas Huth
2018-04-30  7:51 ` Peter Maydell
2018-05-01  3:20 ` Philippe Mathieu-Daudé
2018-05-02  2:20 ` Jason Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=344c0609-0fed-2fe1-1415-24b09e7731f9@redhat.com \
    --to=jasowang@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).