[Libguestfs] [PATCH v3 2/3] do_btrfs_subvolume_list: fix a bad return value

Pino Toscano ptoscano at redhat.com
Tue Jun 16 13:30:39 UTC 2015


On Monday 15 June 2015 11:49:36 Chen Hanxiao wrote:
> don't return a value which is to be freed.
> 
> Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> ---
> v3: don't return internal tmp values.
> 
>  daemon/btrfs.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/daemon/btrfs.c b/daemon/btrfs.c
> index 5011ec4..c1462fd 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];
> @@ -531,16 +531,16 @@ do_btrfs_subvolume_list (const mountable_t *fs)
>      #undef XSTRTOU64
>  
>      memmove (line, line + ovector[6], ovector[7] - ovector[6] + 1);
> -    this->btrfssubvolume_path = line;
> +    this->btrfssubvolume_path = strdup (line);
> +    if (this->btrfssubvolume_path == NULL)
> +      goto error;
>    }

Instead of moving bytes in 'line', since you know the start of the
string and how many characters were matched for it, use strndup
directly from the starting byte. Something like:

 this->btrfssubvolume_path = 
   strndup (line + ovector[6], ovector[7] - ovector[6]);

Thanks,
-- 
Pino Toscano




More information about the Libguestfs mailing list