qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic()


From: Jason Wang
Subject: Re: [Qemu-devel] [PATCH] net: Fix memory leak in net_param_nic()
Date: Wed, 2 May 2018 10:20:21 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0



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 <address@hidden>
---
  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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]