From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP1af-0007bp-Fl for qemu-devel@nongnu.org; Mon, 18 Jul 2016 01:59:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bP1ab-0002Hs-Cg for qemu-devel@nongnu.org; Mon, 18 Jul 2016 01:59:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bP1ab-0002Hm-4Z for qemu-devel@nongnu.org; Mon, 18 Jul 2016 01:59:37 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9198C00FBBA for ; Mon, 18 Jul 2016 05:59:36 +0000 (UTC) References: <1468572967-27979-1-git-send-email-pbonzini@redhat.com> From: Jason Wang Message-ID: <578C7045.706@redhat.com> Date: Mon, 18 Jul 2016 13:59:33 +0800 MIME-Version: 1.0 In-Reply-To: <1468572967-27979-1-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] tap: fix memory leak on failure to create a multiqueue tap device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org On 2016=E5=B9=B407=E6=9C=8815=E6=97=A5 16:56, Paolo Bonzini wrote: > Reported by Coverity. > > Signed-off-by: Paolo Bonzini > --- > net/tap.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/net/tap.c b/net/tap.c > index e9c32f3..6a2cedc 100644 > --- a/net/tap.c > +++ b/net/tap.c > @@ -787,8 +787,8 @@ int net_init_tap(const NetClientOptions *opts, cons= t char *name, > return -1; > } > } else if (tap->has_fds) { > - char **fds =3D g_new(char *, MAX_TAP_QUEUES); > - char **vhost_fds =3D g_new(char *, MAX_TAP_QUEUES); > + char **fds =3D g_new0(char *, MAX_TAP_QUEUES); > + char **vhost_fds =3D g_new0(char *, MAX_TAP_QUEUES); > int nfds, nvhosts; > =20 > if (tap->has_ifname || tap->has_script || tap->has_downscript= || > @@ -806,7 +806,7 @@ int net_init_tap(const NetClientOptions *opts, cons= t char *name, > if (nfds !=3D nvhosts) { > error_setg(errp, "The number of fds passed does not m= atch " > "the number of vhostfds passed"); > - return -1; > + goto free_fail; > } > } > =20 > @@ -814,7 +814,7 @@ int net_init_tap(const NetClientOptions *opts, cons= t char *name, > fd =3D monitor_fd_param(cur_mon, fds[i], &err); > if (fd =3D=3D -1) { > error_propagate(errp, err); > - return -1; > + goto free_fail; > } > =20 > fcntl(fd, F_SETFL, O_NONBLOCK); > @@ -824,7 +824,7 @@ int net_init_tap(const NetClientOptions *opts, cons= t char *name, > } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fd)) { > error_setg(errp, > "vnet_hdr not consistent across given tap = fds"); > - return -1; > + goto free_fail; > } > =20 > net_init_tap_one(tap, peer, "tap", name, ifname, > @@ -833,11 +833,21 @@ int net_init_tap(const NetClientOptions *opts, co= nst char *name, > vnet_hdr, fd, &err); > if (err) { > error_propagate(errp, err); > - return -1; > + goto free_fail; > } > } > g_free(fds); > g_free(vhost_fds); > + return 0; > + > +free_fail: > + for (i =3D 0; i < nfds; i++) { > + g_free(fds[i]); > + g_free(vhost_fds[i]); > + } > + g_free(fds); > + g_free(vhost_fds); > + return -1; > } else if (tap->has_helper) { > if (tap->has_ifname || tap->has_script || tap->has_downscript= || > tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds= ) { Applied to -net. Thanks