]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
When an item is added to an array, then the array is realloc()ed (to size+1), 3877/head
authorTomasz Blaszczak <tomasz.blaszczak@consult.red>
Wed, 23 Jun 2021 07:17:05 +0000 (09:17 +0200)
committerTomasz Blaszczak <tomasz.blaszczak@consult.red>
Tue, 29 Jun 2021 06:20:51 +0000 (08:20 +0200)
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: Tomasz Blaszczak <tomasz.blaszczak@consult.red>
src/lxc/lxccontainer.c

index c533d9dd44e79788d33228c297eb9b380b0e7440..96c3ee31ba933bddd7522a94557888084b14a455 100644 (file)
@@ -2326,7 +2326,7 @@ static bool remove_from_array(char ***names, char *cname, int size)
                char **newnames = (char**)realloc(*names, (size-1) * sizeof(char *));
                if (!newnames) {
                        ERROR("Out of memory");
-                       return false;
+                       return true;
                }
 
                *names = newnames;