
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@redhat.com> 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@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list