Sometimes the length of the string list is known but the array isn't
NULL terminated. Add helper to free the array in such cases.
---
src/libvirt_private.syms | 1 +
src/util/virstring.c | 20 ++++++++++++++++++++
src/util/virstring.h | 1 +
3 files changed, 22 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ee745ea..cb1fd72 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1901,6 +1901,7 @@ virStrcpy;
virStrdup;
virStringArrayHasString;
virStringFreeList;
+virStringFreeListCount;
virStringJoin;
virStringListLength;
virStringReplace;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 6dcc7a8..35b99a5 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -187,6 +187,26 @@ void virStringFreeList(char **strings)
}
+/**
+ * virStringFreeListCount:
+ * @strings: array of strings to free
+ * @count: number of elements in the array
+ *
+ * Frees a string array of @count length.
+ */
+void
+virStringFreeListCount(char **strings,
+ size_t count)
+{
+ size_t i;
+
+ for (i = 0; i < count; i++)
+ VIR_FREE(strings[i]);
+
+ VIR_FREE(strings);
+}
+
+
bool
virStringArrayHasString(char **strings, const char *needle)
{
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 0ab9d96..42d68b5 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -42,6 +42,7 @@ char *virStringJoin(const char **strings,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void virStringFreeList(char **strings);
+void virStringFreeListCount(char **strings, size_t count);
bool virStringArrayHasString(char **strings, const char *needle);
--
1.9.3