Re: [PATCH v2 01/22] util: Introduce virStringListCopy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 10/13/2017 03:07 PM, Jiri Denemark wrote:
> On Fri, Oct 13, 2017 at 20:14:33 +0200, Jiri Denemark wrote:
>> diff --git a/src/util/virstring.c b/src/util/virstring.c
>> index 0288d1e677..820b282ac5 100644
>> --- a/src/util/virstring.c
>> +++ b/src/util/virstring.c
>> @@ -239,6 +239,43 @@ virStringListRemove(char ***strings,
>>  }
>>  

re - Reviewed-by: John Ferlan <jferlan@xxxxxxxxxx>

John

>>  
>> +/**
>> + * virStringListCopy:
>> + * @dst: where to store the copy of @strings
>> + * @src: a NULL-terminated array of strings
>> + *
>> + * Makes a deep copy of the @src string list and stores it in @dst. Callers
>> + * are responsible for freeing both @dst and @src.
>> + *
>> + * Returns 0 on success, -1 on error.
>> + */
>> +int
>> +virStringListCopy(char ***dst,
>> +                  const char **src)
>> +{
>> +    char **copy = NULL;
>> +    size_t i;
>> +
>> +    if (!src)
>> +        return 0;
>> +
>> +    if (VIR_ALLOC_N(copy, virStringListLength(src) + 1) < 0)
>> +        goto error;
>> +
>> +    for (i = 0; src[i]; i++) {
>> +        if (VIR_STRDUP(copy[i], src[i]) < 0)
>> +            goto error;
>> +    }
>> +
>> +    *dst = copy;
>> +    return 0;
>> +
>> + error:
>> +    virStringListFree(copy);
>> +    return -1;
>> +}
> 
> Consider the following patch squashed in:
> 
> diff --git a/src/util/virstring.c b/src/util/virstring.c
> index 820b282ac5..eac4774b53 100644
> --- a/src/util/virstring.c
> +++ b/src/util/virstring.c
> @@ -245,7 +245,7 @@ virStringListRemove(char ***strings,
>   * @src: a NULL-terminated array of strings
>   *
>   * Makes a deep copy of the @src string list and stores it in @dst. Callers
> - * are responsible for freeing both @dst and @src.
> + * are responsible for freeing @dst.
>   *
>   * Returns 0 on success, -1 on error.
>   */
> @@ -256,6 +256,8 @@ virStringListCopy(char ***dst,
>      char **copy = NULL;
>      size_t i;
>  
> +    *dst = NULL;
> +
>      if (!src)
>          return 0;
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux