From nobody Sat Nov 1 22:15:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527751832410664.5873731950473; Thu, 31 May 2018 00:30:32 -0700 (PDT) Received: from localhost ([::1]:42382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOI2Z-0005BQ-JI for importer@patchew.org; Thu, 31 May 2018 03:30:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOI1R-0004eb-Ei for qemu-devel@nongnu.org; Thu, 31 May 2018 03:29:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOI1O-00071Q-BD for qemu-devel@nongnu.org; Thu, 31 May 2018 03:29:21 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2627 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fOI1O-0006zn-0R; Thu, 31 May 2018 03:29:18 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B2096E200A759; Thu, 31 May 2018 15:29:03 +0800 (CST) Received: from localhost (10.177.24.66) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 15:28:56 +0800 From: wangyunjian To: Date: Thu, 31 May 2018 15:28:22 +0800 Message-ID: <1527751702-15452-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.177.24.66] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [PATCH v2] tap: fix memory leak on success to create a tap device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jasowang@redhat.com, caihe@huawei.com, qemu-stable@nongnu.org, Yunjian Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yunjian Wang The memory leak on success to create a tap device. And the nfds and nvhosts may not be the same and need to be processed separately. Fixes: 07825977 ("tap: fix memory leak on failure to create a multiqueue ta= p device") Fixes: 264986e2 ("tap: multiqueue support") CC: QEMU Stable Signed-off-by: Yunjian Wang --- v2: -add commit log and cc qemu-stable with fixes tags --- net/tap.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/tap.c b/net/tap.c index de05f20..6d7710f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -803,7 +803,8 @@ int net_init_tap(const Netdev *netdev, const char *name, } else if (tap->has_fds) { char **fds; char **vhost_fds; - int nfds, nvhosts; + int nfds =3D 0, nvhosts =3D 0; + int ret =3D 0; =20 if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || @@ -823,6 +824,7 @@ int net_init_tap(const Netdev *netdev, const char *name, if (nfds !=3D nvhosts) { error_setg(errp, "The number of fds passed does not match " "the number of vhostfds passed"); + ret =3D -1; goto free_fail; } } @@ -831,6 +833,7 @@ int net_init_tap(const Netdev *netdev, const char *name, fd =3D monitor_fd_param(cur_mon, fds[i], &err); if (fd =3D=3D -1) { error_propagate(errp, err); + ret =3D -1; goto free_fail; } =20 @@ -841,6 +844,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fd)) { error_setg(errp, "vnet_hdr not consistent across given tap fds"); + ret =3D -1; goto free_fail; } =20 @@ -850,21 +854,21 @@ int net_init_tap(const Netdev *netdev, const char *na= me, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); + ret =3D -1; goto free_fail; } } - g_free(fds); - g_free(vhost_fds); - return 0; =20 free_fail: + for (i =3D 0; i < nvhosts; i++) { + g_free(vhost_fds[i]); + } 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; + return ret; } 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) { --=20 1.8.3.1