Commit bc5f0449 by Tomasz Blaszczak

When an item is added to an array, then the array is realloc()ed (to size+1),

and the item is copied (strdup()) to the array. Thus, when an item is removed from an array, memory allocated for that item should be freed, successive items should be left-shifted and the array realloc()ed again (size-1). Additional changes: - If strdup() fails in add_to_array(), then an array should be realloc()ed again to original size. - Initialize an array in list_all_containers(). Signed-off-by: 's avatarTomasz Blaszczak <tomasz.blaszczak@consult.red>
parent 5364ae41
...@@ -2326,7 +2326,7 @@ static bool remove_from_array(char ***names, char *cname, int size) ...@@ -2326,7 +2326,7 @@ static bool remove_from_array(char ***names, char *cname, int size)
char **newnames = (char**)realloc(*names, (size-1) * sizeof(char *)); char **newnames = (char**)realloc(*names, (size-1) * sizeof(char *));
if (!newnames) { if (!newnames) {
ERROR("Out of memory"); ERROR("Out of memory");
return false; return true;
} }
*names = newnames; *names = newnames;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment