From: Jeff Mahoney <je...@suse.com> 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 <je...@suse.com> --- 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); -- 2.12.3 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html