From patchwork Mon Feb 25 22:54:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 2182141 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 3C5413FCA4 for ; Mon, 25 Feb 2013 21:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759777Ab3BYVzn (ORCPT ); Mon, 25 Feb 2013 16:55:43 -0500 Received: from nat-pool-rdu.redhat.com ([66.187.233.202]:54656 "EHLO bp-05.lab.msp.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759582Ab3BYVzR (ORCPT ); Mon, 25 Feb 2013 16:55:17 -0500 Received: by bp-05.lab.msp.redhat.com (Postfix, from userid 0) id EBADF1E0A9D; Mon, 25 Feb 2013 16:54:54 -0600 (CST) From: Eric Sandeen To: linux-btrfs@vger.kernel.org Cc: Eric Sandeen Subject: [PATCH 13/17] btrfs-progs: close fd on cmd_subvol_get_default return Date: Mon, 25 Feb 2013 16:54:46 -0600 Message-Id: <1361832890-40921-14-git-send-email-sandeen@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1361832890-40921-1-git-send-email-sandeen@redhat.com> References: <1361832890-40921-1-git-send-email-sandeen@redhat.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Without this we leak the fd when we return from the function. Also, remove the senseless random return values. Signed-off-by: Eric Sandeen --- cmds-subvolume.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index f9258fc..0dfaefe 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -624,7 +624,7 @@ static const char * const cmd_subvol_get_default_usage[] = { static int cmd_subvol_get_default(int argc, char **argv) { - int fd; + int fd = -1; int ret; char *subvol; struct btrfs_list_filter_set *filter_set; @@ -638,35 +638,36 @@ static int cmd_subvol_get_default(int argc, char **argv) ret = test_issubvolume(subvol); if (ret < 0) { fprintf(stderr, "ERROR: error accessing '%s'\n", subvol); - return 12; + return 1; } if (!ret) { fprintf(stderr, "ERROR: '%s' is not a subvolume\n", subvol); - return 13; + return 1; } fd = open_file_or_dir(subvol); if (fd < 0) { fprintf(stderr, "ERROR: can't access '%s'\n", subvol); - return 12; + return 1; } ret = btrfs_list_get_default_subvolume(fd, &default_id); if (ret) { fprintf(stderr, "ERROR: can't perform the search - %s\n", strerror(errno)); - return ret; + goto out; } + ret = 1; if (default_id == 0) { fprintf(stderr, "ERROR: 'default' dir item not found\n"); - return ret; + goto out; } /* no need to resolve roots if FS_TREE is default */ if (default_id == BTRFS_FS_TREE_OBJECTID) { printf("ID 5 (FS_TREE)\n"); - return ret; + goto out; } filter_set = btrfs_list_alloc_filter_set(); @@ -684,8 +685,11 @@ static int cmd_subvol_get_default(int argc, char **argv) if (filter_set) btrfs_list_free_filter_set(filter_set); +out: + if (fd != -1) + close(fd); if (ret) - return 19; + return 1; return 0; }