From patchwork Sun Nov 2 05:37:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 405824 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 0048714007F for ; Sun, 2 Nov 2014 16:38:21 +1100 (AEDT) Received: from localhost ([::1]:55174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xknrn-0003OT-4X for incoming@patchwork.ozlabs.org; Sun, 02 Nov 2014 01:38:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XknrS-00033I-HF for qemu-devel@nongnu.org; Sun, 02 Nov 2014 01:38:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XknrN-0007oI-NS for qemu-devel@nongnu.org; Sun, 02 Nov 2014 01:37:58 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:64122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XknrN-0007o8-0G; Sun, 02 Nov 2014 01:37:53 -0400 Received: from 172.24.2.119 (EHLO szxeml420-hub.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id AWM77708; Sun, 02 Nov 2014 13:37:46 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml420-hub.china.huawei.com (10.82.67.159) with Microsoft SMTP Server id 14.3.158.1; Sun, 2 Nov 2014 13:37:38 +0800 From: To: Date: Sun, 2 Nov 2014 13:37:17 +0800 Message-ID: <1414906637-11048-1-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020209.5455C32B.003E, ss=1, re=0.001, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: d8ec1d18735675ed0414d5a1b2dc4bc6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: qemu-trivial@nongnu.org, Gonglei , mjt@tls.msk.ru, peter.huangpeng@huawei.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2] tap: fix possible fd leak in net_init_tap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei In hotplugging scenario, taking those true branch, the file handler do not be closed. Let's close them before return. Signed-off-by: Gonglei --- v1: [PATCH 2/2] tap: fix possible fd leak v2: add explicit close(fd) and change subject. (Thanks to /mjt) --- net/tap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/tap.c b/net/tap.c index 7bcd4c7..bde6b58 100644 --- a/net/tap.c +++ b/net/tap.c @@ -796,6 +796,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, if (net_init_tap_one(tap, peer, "bridge", name, ifname, script, downscript, vhostfdname, vnet_hdr, fd)) { + close(fd); return -1; } } else { @@ -823,6 +824,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, if (queues > 1 && i == 0 && !tap->has_ifname) { if (tap_fd_get_ifname(fd, ifname)) { error_report("Fail to get ifname"); + close(fd); return -1; } } @@ -831,6 +833,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, i >= 1 ? "no" : script, i >= 1 ? "no" : downscript, vhostfdname, vnet_hdr, fd)) { + close(fd); return -1; } }