[libvirt] [PATCH] fix memory leak in __virStringListFree

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

 



Currently __virStringListFree is freeing only the list nodes, but not
the strings on the list (and neither is anyone else freeing these).
This small patch fixes that, and documents the two __virStringList
functions.

Dave

diff --git a/src/libvirt.c b/src/libvirt.c
index 8fd594b..bee98d2 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -5308,8 +5308,18 @@ virStorageVolGetPath(virStorageVolPtr vol)
 
 
 
-/* Not for public use.  Combines the elements of a virStringList
+/**
+ * __virStringListJoin:
+ * @list: the StringList
+ * @pre: string to prepend to the result string
+ * @post: string to append to the result string
+ * @sep: string to separate the list elements
+ *
+ * Internal function to combine the elements of a virStringList
  * into a single string.
+ *
+ * Returns the resulting string, which the caller is responsible
+ * for freeing when they're done with it.  Returns NULL on error.
  */
 char *__virStringListJoin(const virStringList *list, const char *pre,
                         const char *post, const char *sep)
@@ -5338,10 +5348,17 @@ char *__virStringListJoin(const virStringList *list, const char *pre,
 }
 
 
+/**
+ * __virStringListFree:
+ * @list: the StringList to free
+ *
+ * Internal function to free the memory used by a string list.
+ */
 void __virStringListFree(virStringList *list)
 {
     while (list) {
         virStringList *p = list->next;
+        VIR_FREE(list->val);
         VIR_FREE(list);
         list = p;
     }
--
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]