changeset 37066:1843c6aaae4d

Add listFree(). Use it in listSet(). (This is the only purpose of use at the moment, but we will need listFree() later which is the reason behind setting the pointer to NULL after freeing.)
author ib
date Thu, 24 Apr 2014 11:56:18 +0000
parents b28b632efeef
children b03e0fd957fd
files gui/util/list.c gui/util/list.h
diffstat 2 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gui/util/list.c	Thu Apr 24 11:31:31 2014 +0000
+++ b/gui/util/list.c	Thu Apr 24 11:56:18 2014 +0000
@@ -26,6 +26,7 @@
 #include <string.h>
 
 #include "list.h"
+#include "mem.h"
 #include "string.h"
 #include "gui/app/gui.h"
 
@@ -269,6 +270,25 @@
 }
 
 /**
+ * @brief Free a string list.
+ *
+ * @param list pointer to the string list
+ */
+void listFree(char ***list)
+{
+    if (*list) {
+        char **l = *list;
+
+        while (*l) {
+            free(*l);
+            l++;
+        }
+
+        nfree(*list);
+    }
+}
+
+/**
  * @brief Set string list to @a entry.
  *
  * @param list pointer to the string list
@@ -278,16 +298,7 @@
  */
 void listSet(char ***list, const char *entry)
 {
-    if (*list) {
-        char **l = *list;
-
-        while (*l) {
-            free(*l);
-            l++;
-        }
-
-        free(*list);
-    }
+    listFree(list);
 
     *list = malloc(2 * sizeof(char *));
 
--- a/gui/util/list.h	Thu Apr 24 11:31:31 2014 +0000
+++ b/gui/util/list.h	Thu Apr 24 11:56:18 2014 +0000
@@ -54,6 +54,7 @@
 
 /// @name String list operations
 //@{
+void listFree(char ***list);
 void listRepl(char ***list, const char *search, const char *replace);
 void listSet(char ***list, const char *entry);
 //@}