diff options
-rw-r--r-- | include/stringlist.h | 6 | ||||
-rw-r--r-- | lib/stringlist.c | 10 |
2 files changed, 8 insertions, 8 deletions
diff --git a/include/stringlist.h b/include/stringlist.h index c92354281e..4b3cbf3118 100644 --- a/include/stringlist.h +++ b/include/stringlist.h @@ -5,7 +5,7 @@ struct string_list { struct list_head list; - char str[0]; + char *str; }; int string_list_add(struct string_list *sl, char *str); @@ -22,8 +22,10 @@ static inline void string_list_free(struct string_list *sl) { struct string_list *entry, *safe; - list_for_each_entry_safe(entry, safe, &sl->list, list) + list_for_each_entry_safe(entry, safe, &sl->list, list) { + free(entry->str); free(entry); + } } #endif /* __STRING_H */ diff --git a/lib/stringlist.c b/lib/stringlist.c index a8ff97964f..c8b835ed09 100644 --- a/lib/stringlist.c +++ b/lib/stringlist.c @@ -16,9 +16,8 @@ int string_list_add(struct string_list *sl, char *str) { struct string_list *new; - new = xmalloc(sizeof(struct string_list) + strlen(str) + 1); - - strcpy(new->str, str); + new = xmalloc(sizeof(*new)); + new->str = xstrdup(str); list_add_tail(&new->list, &sl->list); @@ -29,9 +28,8 @@ int string_list_add_sorted(struct string_list *sl, char *str) { struct string_list *new; - new = xmalloc(sizeof(struct string_list) + strlen(str) + 1); - - strcpy(new->str, str); + new = xmalloc(sizeof(*new)); + new->str = xstrdup(str); list_add_sort(&new->list, &sl->list, string_list_compare); |