From patchwork Tue Sep 25 02:02:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 1501731 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 35018DF280 for ; Tue, 25 Sep 2012 02:03:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752136Ab2IYCCp (ORCPT ); Mon, 24 Sep 2012 22:02:45 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:54637 "EHLO e33.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751677Ab2IYCCn (ORCPT ); Mon, 24 Sep 2012 22:02:43 -0400 Received: from /spool/local by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Sep 2012 20:02:43 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 24 Sep 2012 20:02:41 -0600 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 4A5CA1FF003F; Mon, 24 Sep 2012 20:02:37 -0600 (MDT) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8P22eH7206548; Mon, 24 Sep 2012 20:02:40 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q8P22c2g018158; Mon, 24 Sep 2012 20:02:40 -0600 Received: from us.ibm.com (f15.cn.ibm.com [9.115.122.154]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q8P22V15017807; Mon, 24 Sep 2012 20:02:34 -0600 Received: by us.ibm.com (sSMTP sendmail emulation); Tue, 25 Sep 2012 10:02:21 +0800 From: zwu.kernel@gmail.com To: linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jbacik@fusionio.com, dave@jikos.cz, linuxram@linux.vnet.ibm.com, Zhi Yong Wu Subject: [PATCH v2 1/2] btrfs-progs: Close file descriptor on exit Date: Tue, 25 Sep 2012 10:02:15 +0800 Message-Id: <1348538536-29838-2-git-send-email-zwu.kernel@gmail.com> X-Mailer: git-send-email 1.7.6.5 In-Reply-To: <1348538536-29838-1-git-send-email-zwu.kernel@gmail.com> References: <1348538536-29838-1-git-send-email-zwu.kernel@gmail.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12092502-2398-0000-0000-00000B611DEA X-IBM-ISS-SpamDetectors: X-IBM-ISS-DetailInfo: BY=3.00000294; HX=3.00000196; KW=3.00000007; PH=3.00000001; SC=3.00000007; SDB=6.00177036; UDB=6.00040088; UTC=2012-09-25 02:02:43 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Zhi Yong Wu Need to close fd on exit. Signed-off-by: Zhi Yong Wu --- cmds-filesystem.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index b1457de..e62c4fd 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -77,18 +77,23 @@ static int cmd_df(int argc, char **argv) if (ret) { fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n", path, strerror(e)); + close(fd); free(sargs); return ret; } - if (!sargs->total_spaces) + if (!sargs->total_spaces) { + close(fd); return 0; + } count = sargs->total_spaces; sargs = realloc(sargs, sizeof(struct btrfs_ioctl_space_args) + (count * sizeof(struct btrfs_ioctl_space_info))); - if (!sargs) + if (!sargs) { + close(fd); return -ENOMEM; + } sargs->space_slots = count; sargs->total_spaces = 0; @@ -148,6 +153,7 @@ static int cmd_df(int argc, char **argv) printf("%s: total=%s, used=%s\n", description, total_bytes, used_bytes); } + close(fd); free(sargs); return 0;