From patchwork Thu Mar 8 02:40:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 10265925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 37C4D6055B for ; Thu, 8 Mar 2018 02:42:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2964C292B4 for ; Thu, 8 Mar 2018 02:42:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E42B292CD; Thu, 8 Mar 2018 02:42:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C232292B4 for ; Thu, 8 Mar 2018 02:42:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935093AbeCHCmc (ORCPT ); Wed, 7 Mar 2018 21:42:32 -0500 Received: from mx2.suse.de ([195.135.220.15]:60575 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935156AbeCHClC (ORCPT ); Wed, 7 Mar 2018 21:41:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CA57FAE90 for ; Thu, 8 Mar 2018 02:41:00 +0000 (UTC) Received: from sled4.home.jeffm.io (sled4.home.jeffm.io [IPv6:2001:559:c0d4:6f::8]) by mail.home.jeffm.io (Postfix) with ESMTPS id 8279C81AD3E7; Wed, 7 Mar 2018 21:40:33 -0500 (EST) Received: by sled4.home.jeffm.io (Postfix, from userid 1000) id 2585D3A3B; Wed, 7 Mar 2018 21:40:57 -0500 (EST) From: jeffm@suse.com To: linux-btrfs@vger.kernel.org Cc: Jeff Mahoney Subject: [PATCH 05/20] btrfs-progs: btrfs-list: add btrfs_cleanup_root_info Date: Wed, 7 Mar 2018 21:40:32 -0500 Message-Id: <20180308024047.10104-6-jeffm@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180308024047.10104-1-jeffm@suse.com> References: <20180308024047.10104-1-jeffm@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff Mahoney Currently we can pass back root_info structures to callers but have to free the strings manually. This adds a helper to do it and uses it in cmd_subvol_show. Signed-off-by: Jeff Mahoney --- btrfs-list.c | 18 +++++++++++++++--- btrfs-list.h | 1 + cmds-subvolume.c | 5 +---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index 90c98be1..2fe31e9c 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -533,15 +533,27 @@ static int add_root_backref(struct root_lookup *root_lookup, u64 root_id, name_len, 0, 0, 0, NULL, NULL, NULL); } +static void __btrfs_free_root_info_strings(struct root_info *ri) +{ + free(ri->name); + free(ri->path); + free(ri->full_path); +} + +void btrfs_cleanup_root_info(struct root_info *ri) +{ + __btrfs_free_root_info_strings(ri); + ri->name = NULL; + ri->path = NULL; + ri->full_path = NULL; +} static void free_root_info(struct rb_node *node) { struct root_info *ri; ri = to_root_info(node); - free(ri->name); - free(ri->path); - free(ri->full_path); + __btrfs_free_root_info_strings(ri); free(ri); } diff --git a/btrfs-list.h b/btrfs-list.h index 6e5fc778..9d0478b8 100644 --- a/btrfs-list.h +++ b/btrfs-list.h @@ -176,5 +176,6 @@ char *btrfs_list_path_for_root(int fd, u64 root); int btrfs_list_get_path_rootid(int fd, u64 *treeid); int btrfs_get_subvol(int fd, struct root_info *the_ri); int btrfs_get_toplevel_subvol(int fd, struct root_info *the_ri); +void btrfs_cleanup_root_info(struct root_info *ri); #endif diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 8a473f7a..769d2a76 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -1113,10 +1113,7 @@ static int cmd_subvol_show(int argc, char **argv) 1, raw_prefix); out: - /* clean up */ - free(get_ri.path); - free(get_ri.name); - free(get_ri.full_path); + btrfs_cleanup_root_info(&get_ri); free(filter_set); close_file_or_dir(fd, dirstream1);