From patchwork Wed Dec 11 01:20:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 299685 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5E6BA2C0313 for ; Wed, 11 Dec 2013 12:20:15 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751824Ab3LKBUO (ORCPT ); Tue, 10 Dec 2013 20:20:14 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:42476 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751808Ab3LKBUN (ORCPT ); Tue, 10 Dec 2013 20:20:13 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rBB1KB02007451 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Dec 2013 01:20:12 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBB1KAVA017820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Dec 2013 01:20:11 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBB1KAwl022487; Wed, 11 Dec 2013 01:20:10 GMT Received: from localhost (/10.145.179.107) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 10 Dec 2013 17:20:10 -0800 Subject: [PATCH 16/74] debugfs: don't leak fd when calling dump_file To: tytso@mit.edu, darrick.wong@oracle.com From: "Darrick J. Wong" Cc: linux-ext4@vger.kernel.org Date: Tue, 10 Dec 2013 17:20:07 -0800 Message-ID: <20131211012007.30655.55062.stgit@birch.djwong.org> In-Reply-To: <20131211011813.30655.39624.stgit@birch.djwong.org> References: <20131211011813.30655.39624.stgit@birch.djwong.org> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The caller of dump_file provides a fd to write to, so the caller should also dispose of the fd. Also, the fd never gets closed if preserve=1. Signed-off-by: Darrick J. Wong --- debugfs/dump.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/debugfs/dump.c b/debugfs/dump.c index c75b9f1..952a752 100644 --- a/debugfs/dump.c +++ b/debugfs/dump.c @@ -143,8 +143,6 @@ static void dump_file(const char *cmdname, ext2_ino_t ino, int fd, if (preserve) fix_perms("dump_file", &inode, fd, outname); - else if (fd != 1) - close(fd); return; } @@ -191,6 +189,11 @@ void do_dump(int argc, char **argv) } dump_file(argv[0], inode, fd, preserve, out_fn); + if (close(fd) != 0) { + com_err(argv[0], errno, "while closing %s for dump_inode", + out_fn); + return; + } return; } @@ -273,6 +276,10 @@ static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode, goto errout; } dump_file("rdump", ino, fd, 1, fullname); + if (close(fd) != 0) { + com_err("rdump", errno, "while dumping %s", fullname); + goto errout; + } } else if (LINUX_S_ISDIR(inode->i_mode) && strcmp(name, ".") && strcmp(name, "..")) { errcode_t retval;