From patchwork Wed Sep 5 09:21:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhi Yong Wu X-Patchwork-Id: 1407251 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id B98953FC71 for ; Wed, 5 Sep 2012 09:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758485Ab2IEJV1 (ORCPT ); Wed, 5 Sep 2012 05:21:27 -0400 Received: from e3.ny.us.ibm.com ([32.97.182.143]:40403 "EHLO e3.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758398Ab2IEJVZ (ORCPT ); Wed, 5 Sep 2012 05:21:25 -0400 Received: from /spool/local by e3.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Sep 2012 05:21:24 -0400 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e3.ny.us.ibm.com (192.168.1.103) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 5 Sep 2012 05:21:22 -0400 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 40839C90043; Wed, 5 Sep 2012 05:21:22 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q859LLBc33161364; Wed, 5 Sep 2012 05:21:21 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q859LL56002089; Wed, 5 Sep 2012 06:21:21 -0300 Received: from us.ibm.com (f15.cn.ibm.com [9.115.122.154]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q859LIr2001946; Wed, 5 Sep 2012 06:21:18 -0300 Received: by us.ibm.com (sSMTP sendmail emulation); Wed, 5 Sep 2012 17:21:12 +0800 From: Zhi Yong Wu To: linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linuxram@linux.vnet.ibm.com, Zhi Yong Wu Subject: [PATCH v2 1/2] btrfs-progs: Close file descriptor on exit Date: Wed, 5 Sep 2012 17:21:06 +0800 Message-Id: <1346836867-1060-2-git-send-email-wuzhy@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.6.5 In-Reply-To: <1346836867-1060-1-git-send-email-wuzhy@linux.vnet.ibm.com> References: <1346836867-1060-1-git-send-email-wuzhy@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12090509-8974-0000-0000-00000D1E0ED7 X-IBM-ISS-SpamDetectors: X-IBM-ISS-DetailInfo: BY=3.00000293; HX=3.00000196; KW=3.00000007; PH=3.00000001; SC=3.00000007; SDB=6.00171462; UDB=6.00038889; UTC=2012-09-05 09:21:23 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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;