From patchwork Fri Jan 20 03:07:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 92025 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp589191qgi; Thu, 19 Jan 2017 19:18:10 -0800 (PST) X-Received: by 10.200.56.211 with SMTP id g19mr10289013qtc.177.1484882290775; Thu, 19 Jan 2017 19:18:10 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 42si3978201qtv.293.2017.01.19.19.18.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 19 Jan 2017 19:18:10 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:52266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUPiK-0007H8-7i for patch@linaro.org; Thu, 19 Jan 2017 22:18:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUPYh-0000WG-UN for qemu-devel@nongnu.org; Thu, 19 Jan 2017 22:08:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cUPYg-0002uV-WD for qemu-devel@nongnu.org; Thu, 19 Jan 2017 22:08:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54332) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cUPYg-0002uG-QA for qemu-devel@nongnu.org; Thu, 19 Jan 2017 22:08:10 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 0CB143B721; Fri, 20 Jan 2017 03:08:11 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-6-106.pek2.redhat.com [10.72.6.106]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0K37r7f014507; Thu, 19 Jan 2017 22:08:09 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Fri, 20 Jan 2017 11:07:50 +0800 Message-Id: <1484881670-24237-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1484881670-24237-1-git-send-email-jasowang@redhat.com> References: <1484881670-24237-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 20 Jan 2017 03:08:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/6] tap: fix memory leak on failure in net_init_tap() 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: Jason Wang Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Commit 091a6b2ac fixed most of the memory leaks in failure paths in net_init_tap() reported by Coverity (CID 1356216), but missed one. Fix it by deferring the allocation of fds and vhost_fds until after the error check. Signed-off-by: Peter Maydell Signed-off-by: Jason Wang --- net/tap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/net/tap.c b/net/tap.c index b6896a7..6248e85 100644 --- a/net/tap.c +++ b/net/tap.c @@ -788,8 +788,8 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } } else if (tap->has_fds) { - char **fds = g_new0(char *, MAX_TAP_QUEUES); - char **vhost_fds = g_new0(char *, MAX_TAP_QUEUES); + char **fds; + char **vhost_fds; int nfds, nvhosts; if (tap->has_ifname || tap->has_script || tap->has_downscript || @@ -801,6 +801,9 @@ int net_init_tap(const Netdev *netdev, const char *name, return -1; } + fds = g_new0(char *, MAX_TAP_QUEUES); + vhost_fds = g_new0(char *, MAX_TAP_QUEUES); + nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES); if (tap->has_vhostfds) { nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);