string_list_free - try to be safer

This commit is contained in:
twinaphex 2019-05-22 05:28:20 +02:00
parent 9c12037c43
commit 15e7078361
1 changed files with 9 additions and 6 deletions

View File

@ -41,15 +41,18 @@ void string_list_free(struct string_list *list)
if (!list) if (!list)
return; return;
for (i = 0; i < list->size; i++) if (list->elems)
{ {
if (list->elems[i].data) for (i = 0; i < list->size; i++)
free(list->elems[i].data); {
list->elems[i].data = NULL; if (list->elems[i].data)
free(list->elems[i].data);
list->elems[i].data = NULL;
}
free(list->elems);
} }
if (list->elems)
free(list->elems);
list->elems = NULL; list->elems = NULL;
free(list); free(list);
} }