Skip to content

Commit

Permalink
commands_utils: don't leak memory
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 8, 2021
1 parent c9186cc commit 639428e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/lxc/commands_utils.c
Expand Up @@ -166,28 +166,27 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
__do_free struct lxc_list *tmplist = NULL;
int state;

newclient = malloc(sizeof(*newclient));
newclient = zalloc(sizeof(*newclient));
if (!newclient)
return -ENOMEM;

/* copy requested states */
memcpy(newclient->states, states, sizeof(newclient->states));
newclient->clientfd = state_client_fd;

tmplist = malloc(sizeof(*tmplist));
tmplist = zalloc(sizeof(*tmplist));
if (!tmplist)
return -ENOMEM;

state = handler->state;
if (states[state] != 1) {
lxc_list_add_elem(tmplist, newclient);
lxc_list_add_tail(&handler->conf->state_clients, tmplist);
lxc_list_add_elem(tmplist, move_ptr(newclient));
lxc_list_add_tail(&handler->conf->state_clients, move_ptr(tmplist));
} else {
TRACE("Container already in requested state");
return state;
}

move_ptr(newclient);
move_ptr(tmplist);
TRACE("Added state client fd %d to state client list", state_client_fd);
return MAX_STATE;
}

0 comments on commit 639428e

Please sign in to comment.