All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic()
@ 2018-04-30  7:26 Thomas Huth
  2018-04-30  7:51 ` Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thomas Huth @ 2018-04-30  7:26 UTC (permalink / raw)
  To: Jason Wang, qemu-devel; +Cc: Peter Maydell

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;
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic()
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2018-04-30  7:51 UTC (permalink / raw)
  To: Thomas Huth; +Cc: Jason Wang, QEMU Developers

On 30 April 2018 at 08:26, Thomas Huth <thuth@redhat.com> 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>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic()
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-05-01  3:20 UTC (permalink / raw)
  To: Thomas Huth, Jason Wang, qemu-devel; +Cc: Peter Maydell

On 04/30/2018 04:26 AM, 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>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  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;
>  }
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic()
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2018-05-02  2:20 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel; +Cc: Peter Maydell



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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-02  2:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.