From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lu7zZ-0008KY-Lc for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:29:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lu7zS-0008GM-Ja for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:29:38 -0400 Received: from [199.232.76.173] (port=54434 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lu7zR-0008Fi-JK for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:29:33 -0400 Received: from mail11.svc.cra.dublin.eircom.net ([159.134.118.27]:31193) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1Lu7zQ-00062b-Jk for qemu-devel@nongnu.org; Wed, 15 Apr 2009 12:29:33 -0400 From: Mark McLoughlin Date: Wed, 15 Apr 2009 17:29:23 +0100 Message-Id: <1239812969-8320-4-git-send-email-markmc@redhat.com> In-Reply-To: <1239812969-8320-3-git-send-email-markmc@redhat.com> References: <1239812969-8320-1-git-send-email-markmc@redhat.com> <1239812969-8320-2-git-send-email-markmc@redhat.com> <1239812969-8320-3-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 3/9] Fix error handling in net_client_init() Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Jan Kiszka , qemu-devel@nongnu.org, Mark McLoughlin We weren't freeing the name string everywhere. Signed-off-by: Mark McLoughlin --- net.c | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) diff --git a/net.c b/net.c index 5e6895c..2383b10 100644 --- a/net.c +++ b/net.c @@ -1610,7 +1610,8 @@ int net_client_init(const char *device, const char *p) if (idx == -1 || nb_nics >= MAX_NICS) { fprintf(stderr, "Too Many NICs\n"); - return -1; + ret = -1; + goto out; } nd = &nd_table[idx]; macaddr = nd->macaddr; @@ -1624,7 +1625,8 @@ int net_client_init(const char *device, const char *p) if (get_param_value(buf, sizeof(buf), "macaddr", p)) { if (parse_macaddr(macaddr, buf) < 0) { fprintf(stderr, "invalid syntax for ethernet address\n"); - return -1; + ret = -1; + goto out; } } if (get_param_value(buf, sizeof(buf), "model", p)) { @@ -1664,8 +1666,9 @@ int net_client_init(const char *device, const char *p) port = strtol(p, &devname, 10); devname++; if (port < 1 || port > 65535) { - fprintf(stderr, "vmchannel wrong port number\n"); - return -1; + fprintf(stderr, "vmchannel wrong port number\n"); + ret = -1; + goto out; } vmc = malloc(sizeof(struct VMChannel)); snprintf(name, 20, "vmchannel%ld", port); @@ -1673,7 +1676,8 @@ int net_client_init(const char *device, const char *p) if (!vmc->hd) { fprintf(stderr, "qemu: could not open vmchannel device" "'%s'\n", devname); - return -1; + ret = -1; + goto out; } vmc->port = port; slirp_add_exec(3, vmc->hd, 4, port); @@ -1687,7 +1691,8 @@ int net_client_init(const char *device, const char *p) char ifname[64]; if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { fprintf(stderr, "tap: no interface name\n"); - return -1; + ret = -1; + goto out; } vlan->nb_host_devs++; ret = tap_win32_init(vlan, device, name, ifname); @@ -1734,7 +1739,8 @@ int net_client_init(const char *device, const char *p) ret = net_socket_mcast_init(vlan, device, name, buf); } else { fprintf(stderr, "Unknown socket options: %s\n", p); - return -1; + ret = -1; + goto out; } vlan->nb_host_devs++; } else @@ -1764,13 +1770,13 @@ int net_client_init(const char *device, const char *p) #endif { fprintf(stderr, "Unknown network device: %s\n", device); - if (name) - free(name); - return -1; + ret = -1; + goto out; } if (ret < 0) { fprintf(stderr, "Could not initialize device '%s'\n", device); } +out: if (name) free(name); return ret; -- 1.6.0.6