--- a/src/string_list.c Wed May 22 10:57:17 2013 +0200 +++ b/src/string_list.c Wed May 22 13:00:36 2013 +0200 @@ -40,19 +40,28 @@ } void destroy_string_list_t(string_list_t* list) { - if (list->items != NULL) { - free(list->items); - } - free(list); -} - -void add_string(string_list_t* list, char* item) { - char** reallocated_list = - realloc(list->items, sizeof(char*) * (list->count + 1)); - if (reallocated_list != NULL) { - list->items = reallocated_list; - list->items[list->count] = item; - list->count++; + if (list) { + if (list->items) { + free(list->items); + } + free(list); } } +/* Adds an item to the list, if a NULL-list is specified, the item will + * be freed. This way a NULL-list can be used as garbage bin. + */ +void add_string(string_list_t* list, char* item) { + if (list) { + char** reallocated_list = + realloc(list->items, sizeof(char*) * (list->count + 1)); + if (reallocated_list != NULL) { + list->items = reallocated_list; + list->items[list->count] = item; + list->count++; + } + } else { + free(item); + } +} +