]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxccontainer: improve add_to_clist()
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 14:00:45 +0000 (16:00 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 14:00:45 +0000 (16:00 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxccontainer.c

index 0ac5abdc5ca2989a1eb4b0f4dc1988fa2d1db108..ee521d89afcb08181f8c5fa6e8896b958986b6b2 100644 (file)
@@ -2284,13 +2284,12 @@ static bool add_to_array(char ***names, char *cname, int pos)
 static bool add_to_clist(struct lxc_container ***list, struct lxc_container *c,
                         int pos, bool sort)
 {
-       struct lxc_container **newlist = realloc(*list, (pos + 1) * sizeof(struct lxc_container *));
-       if (!newlist) {
-               ERROR("Out of memory");
-               return false;
-       }
+       struct lxc_container **newlist;
+
+       newlist = realloc(*list, (pos + 1) * sizeof(struct lxc_container *));
+       if (!newlist)
+               return ret_set_errno(false, ENOMEM);
 
-       *list = newlist;
        newlist[pos] = c;
 
        /* Sort the array as we will use binary search on it. */
@@ -2298,6 +2297,7 @@ static bool add_to_clist(struct lxc_container ***list, struct lxc_container *c,
                qsort(newlist, pos + 1, sizeof(struct lxc_container *),
                      (int (*)(const void *, const void *))container_cmp);
 
+       *list = newlist;
        return true;
 }