From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrL6b-00034u-8x for qemu-devel@nongnu.org; Thu, 20 Nov 2014 01:20:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XrL6V-0003wH-UO for qemu-devel@nongnu.org; Thu, 20 Nov 2014 01:20:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32918) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrL6V-0003vz-Gl for qemu-devel@nongnu.org; Thu, 20 Nov 2014 01:20:31 -0500 Message-ID: <546D8825.9070907@redhat.com> Date: Thu, 20 Nov 2014 14:20:21 +0800 From: Jason Wang MIME-Version: 1.0 References: <1416463034-8264-1-git-send-email-arei.gonglei@huawei.com> <1416463034-8264-2-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1416463034-8264-2-git-send-email-arei.gonglei@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/4] net/slirp: fix memory leak List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com, qemu-devel@nongnu.org Cc: pbonzini@redhat.com, peter.huangpeng@huawei.com, stefanha@redhat.com, Alexander Graf On 11/20/2014 01:57 PM, arei.gonglei@huawei.com wrote: > From: Gonglei > > commit b412eb61 introduce 'cmd:' target for guestfwd, > and fwd don't be used in this scenario, and will leak > memory in true branch with 'cmd:'. Let's allocate memory > for fwd variable just in else statement. > > Cc: Alexander Graf > Signed-off-by: Gonglei > --- > net/slirp.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/net/slirp.c b/net/slirp.c > index dc89e6b..377d7ef 100644 > --- a/net/slirp.c > +++ b/net/slirp.c > @@ -643,17 +643,16 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, > goto fail_syntax; > } > > - fwd = g_malloc(sizeof(struct GuestFwd)); > snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port); > > if ((strlen(p) > 4) && !strncmp(p, "cmd:", 4)) { > if (slirp_add_exec(s->slirp, 0, &p[4], &server, port) < 0) { > error_report("conflicting/invalid host:port in guest forwarding " > "rule '%s'", config_str); > - g_free(fwd); > return -1; > } > } else { > + fwd = g_malloc(sizeof(struct GuestFwd)); > fwd->hd = qemu_chr_new(buf, p, NULL); > if (!fwd->hd) { > error_report("could not open guest forwarding device '%s'", buf); Reviewed-by: Jason Wang