]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_user_nic: cleanup append_alloted()
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 31 Mar 2021 13:59:34 +0000 (15:59 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 1 Apr 2021 08:27:38 +0000 (10:27 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cmd/lxc_user_nic.c

index 06f195a3768370d675bc0292e01a845b105ea186..d8ce1a8421000f656a6c3fde8f7323c724da580f 100644 (file)
@@ -233,10 +233,10 @@ struct alloted_s {
        struct alloted_s *next;
 };
 
-static struct alloted_s *append_alloted(struct alloted_s **head, char *name,
-                                       int n)
+static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int n)
 {
-       struct alloted_s *cur, *al;
+       __do_free struct alloted_s *al = NULL;
+       struct alloted_s *cur;
 
        if (!head || !name) {
                /* Sanity check. Parameters should not be null. */
@@ -244,32 +244,29 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name,
                return NULL;
        }
 
-       al = malloc(sizeof(struct alloted_s));
+       al = zalloc(sizeof(struct alloted_s));
        if (!al) {
                CMD_SYSERROR("Failed to allocate memory\n");
                return NULL;
        }
 
        al->name = strdup(name);
-       if (!al->name) {
-               free(al);
+       if (!al->name)
                return NULL;
-       }
 
        al->allowed = n;
        al->next = NULL;
 
-       if (!*head) {
+       if (*head) {
+               cur = *head;
+               while (cur->next)
+                       cur = cur->next;
+               cur->next = al;
+       } else {
                *head = al;
-               return al;
        }
 
-       cur = *head;
-       while (cur->next)
-               cur = cur->next;
-       cur->next = al;
-
-       return al;
+       return move_ptr(al);
 }
 
 static void free_alloted(struct alloted_s **head)