# HG changeset patch # User ib # Date 1398340578 0 # Node ID 1843c6aaae4d81595f2d48b24ba249bb089fb2a5 # Parent b28b632efeefbc0acc8255caeef7a6ae0567abde 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.) diff -r b28b632efeef -r 1843c6aaae4d gui/util/list.c --- 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 #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 *)); diff -r b28b632efeef -r 1843c6aaae4d gui/util/list.h --- 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); //@}