Chen Hanxiao
2015-Jun-12 09:24 UTC
[Libguestfs] [PATCH v2] btrfs: use CLEANUP_FREE_STRING_LIST for list free
As Pino's comment, we should take advantage of macro CLEANUP_FREE_STRING_LIST. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- v2: initialize variable of CLEANUP_FREE_STRING_LIST to null daemon/btrfs.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index 39392f7..3ca39ab 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -409,7 +409,7 @@ umount (char *fs_buf, const mountable_t *fs) guestfs_int_btrfssubvolume_list * do_btrfs_subvolume_list (const mountable_t *fs) { - char **lines; + CLEANUP_FREE_STRING_LIST char **lines = NULL; size_t i = 0; const size_t MAX_ARGS = 64; const char *argv[MAX_ARGS]; @@ -534,13 +534,11 @@ do_btrfs_subvolume_list (const mountable_t *fs) this->btrfssubvolume_path = line; } - free (lines); pcre_free (re); return ret; error: - free_stringslen (lines, nr_subvolumes); if (ret) free (ret->guestfs_int_btrfssubvolume_list_val); free (ret); if (re) pcre_free (re); @@ -1253,8 +1251,8 @@ do_btrfs_qgroup_show (const char *path) CLEANUP_FREE char *path_buf = NULL; CLEANUP_FREE char *err = NULL; CLEANUP_FREE char *out = NULL; + CLEANUP_FREE_STRING_LIST char **lines = NULL; int r; - char **lines; path_buf = sysroot_path (path); if (path_buf == NULL) { @@ -1323,11 +1321,9 @@ do_btrfs_qgroup_show (const char *path) this->btrfsqgroup_id = line; } - free (lines); return ret; error: - free_stringslen (lines, nr_qgroups + 2); if (ret) free (ret->guestfs_int_btrfsqgroup_list_val); free (ret); @@ -1704,10 +1700,10 @@ do_btrfs_balance_status (const char *path) size_t i = 0; CLEANUP_FREE char *path_buf = NULL; CLEANUP_FREE char *err = NULL; + CLEANUP_FREE_STRING_LIST char **lines = NULL; char *out; int r; guestfs_int_btrfsbalance *ret; - char **lines; size_t nlines; const char *errptr; int erroffset; @@ -1830,10 +1826,10 @@ do_btrfs_scrub_status (const char *path) size_t i = 0; CLEANUP_FREE char *path_buf = NULL; CLEANUP_FREE char *err = NULL; + CLEANUP_FREE_STRING_LIST char **lines = NULL; char *out; int r; guestfs_int_btrfsscrub *ret; - char **lines; path_buf = sysroot_path (path); if (path_buf == NULL) { -- 2.1.0
Pino Toscano
2015-Jun-12 11:41 UTC
Re: [Libguestfs] [PATCH v2] btrfs: use CLEANUP_FREE_STRING_LIST for list free
On Friday 12 June 2015 17:24:59 Chen Hanxiao wrote:> As Pino's comment, we should take advantage of > macro CLEANUP_FREE_STRING_LIST. > > Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> > --- > [...] > @@ -1253,8 +1251,8 @@ do_btrfs_qgroup_show (const char *path) > CLEANUP_FREE char *path_buf = NULL; > CLEANUP_FREE char *err = NULL; > CLEANUP_FREE char *out = NULL; > + CLEANUP_FREE_STRING_LIST char **lines = NULL; > int r; > - char **lines; > > path_buf = sysroot_path (path); > if (path_buf == NULL) {This change causes the daemon to crash, because currently the line buffers are used as return values. Also, tests/btrfs/test-btrfs-subvolume-default.pl hangs. Please make sure that all the tests (`make check`) pass. -- Pino Toscano
Reasonably Related Threads
- [PATCH] btrfs: use CLEANUP_FREE_STRING_LIST for list free
- [PATCH v3 0/3] btrfs: use CLEANUP_FREE_STRING_LIST for list free
- [PATCH v4 0/3] btrfs: use CLEANUP_FREE_STRING_LIST for list free
- [PATCH v2 3/3] btrfs: use CLEANUP_FREE_STRING_LIST for list free
- Re: [PATCH v4 1/3] do_btrfs_qgroup_show: fix a bad return value