lxc_user_nic: cleanup append_alloted()

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