From patchwork Fri Jul 15 08:56:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 648721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rrRKD2Qfpz9s2Q for ; Fri, 15 Jul 2016 18:57:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=XSAMgbR8; dkim-atps=neutral Received: from localhost ([::1]:59263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNyvu-00079B-38 for incoming@patchwork.ozlabs.org; Fri, 15 Jul 2016 04:57:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNyuv-0006ZD-3L for qemu-devel@nongnu.org; Fri, 15 Jul 2016 04:56:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNyuo-0003a9-Kk for qemu-devel@nongnu.org; Fri, 15 Jul 2016 04:56:16 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:34621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNyuo-0003a5-E9 for qemu-devel@nongnu.org; Fri, 15 Jul 2016 04:56:10 -0400 Received: by mail-wm0-x243.google.com with SMTP id q128so1349738wma.1 for ; Fri, 15 Jul 2016 01:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=maEbfAAhIymbCZuhbn+DphNgXcEL0iwjyQz6g4OiZno=; b=XSAMgbR80sVsnjG6RiaB8atrJs69J6blngbXGDHIaG2NLkEpSi6jaWw6tU4oGm7oGN ThCFDLlausD5fwt805Scw6ri6llAGi2yAGJ8SfFTkZd0F7fbY1MxXDIgeb/NqcViQJV0 d/DwRigEeUbersy0swyPiv2XNCDkMHHVq0BNTyPCD+nn+VXNMxzio4qJIeCnxN7DMKgf 3nhI6sFw2s8x/MRMljHfYASrRdP2UcbxwpD+YUXQBaJP56K7wVzj1a+cIS6XuFldqc4K ZGEO8oqPPViMiN/Y8/6Tigg570EwcsTD2iCaYzj+tms/QKa30BAdMBvxcdvGa8ZxJJHe 4G9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=maEbfAAhIymbCZuhbn+DphNgXcEL0iwjyQz6g4OiZno=; b=JEb41G5MXDbJQVshAS/nlaTuyHVj5nsXIQg+4s/gcWP9UiblC8DfBM53XKWCla6Oyk GUhf8cbctu5yCi/8QpWD4eUp6MCLpxY8w+jarFv78L/Q7daC4ELfde6kgrNxnlSbkNnO w2YsRadWxRjxcDTuuZDxrqCF3IkMwOP8yWgthOCBPEIxoetBgi86bOQOJM3/nTZ7vInj gQ/u7VIIxCGTBmZJBBWNrEghZcG337qd+O7/0dKoz4S/5Oit7IUj+SILhl6bO4osVvOz 7HZPoDSz9881aNzwufbDcicbK5HBN13idHZf++Ju8Fo4jhGSsA9G4lXpuew4Hs/hkZdT +IlA== X-Gm-Message-State: ALyK8tKWFmwVBdoq1ut5yoR3SUH/FjPLyVYC+4GP+yKDewbFlYXYJAAaDRXNzAU09WuKQw== X-Received: by 10.28.223.139 with SMTP id w133mr16341754wmg.90.1468572969595; Fri, 15 Jul 2016 01:56:09 -0700 (PDT) Received: from donizetti.redhat.com (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id o142sm1189691wme.20.2016.07.15.01.56.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jul 2016 01:56:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 15 Jul 2016 10:56:07 +0200 Message-Id: <1468572967-27979-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH] tap: fix memory leak on failure to create a multiqueue 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 Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, const char *name, return -1; } } else if (tap->has_fds) { - char **fds = g_new(char *, MAX_TAP_QUEUES); - char **vhost_fds = g_new(char *, MAX_TAP_QUEUES); + char **fds = g_new0(char *, MAX_TAP_QUEUES); + char **vhost_fds = g_new0(char *, MAX_TAP_QUEUES); int nfds, nvhosts; if (tap->has_ifname || tap->has_script || tap->has_downscript || @@ -806,7 +806,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, if (nfds != nvhosts) { error_setg(errp, "The number of fds passed does not match " "the number of vhostfds passed"); - return -1; + goto free_fail; } } @@ -814,7 +814,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, fd = monitor_fd_param(cur_mon, fds[i], &err); if (fd == -1) { error_propagate(errp, err); - return -1; + goto free_fail; } fcntl(fd, F_SETFL, O_NONBLOCK); @@ -824,7 +824,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) { error_setg(errp, "vnet_hdr not consistent across given tap fds"); - return -1; + goto free_fail; } net_init_tap_one(tap, peer, "tap", name, ifname, @@ -833,11 +833,21 @@ int net_init_tap(const NetClientOptions *opts, const 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 = 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) {