commands_utils: auto free lxc_add_state_client

parent b02dc0d9
...@@ -191,9 +191,9 @@ int lxc_cmd_connect(const char *name, const char *lxcpath, ...@@ -191,9 +191,9 @@ int lxc_cmd_connect(const char *name, const char *lxcpath,
int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler, int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
lxc_state_t states[MAX_STATE]) lxc_state_t states[MAX_STATE])
{ {
__do_free struct lxc_state_client *newclient = NULL;
__do_free struct lxc_list *tmplist = NULL;
int state; int state;
struct lxc_state_client *newclient;
struct lxc_list *tmplist;
newclient = malloc(sizeof(*newclient)); newclient = malloc(sizeof(*newclient));
if (!newclient) if (!newclient)
...@@ -204,21 +204,19 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler, ...@@ -204,21 +204,19 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
newclient->clientfd = state_client_fd; newclient->clientfd = state_client_fd;
tmplist = malloc(sizeof(*tmplist)); tmplist = malloc(sizeof(*tmplist));
if (!tmplist) { if (!tmplist)
free(newclient);
return -ENOMEM; return -ENOMEM;
}
state = handler->state; state = handler->state;
if (states[state] != 1) { if (states[state] != 1) {
lxc_list_add_elem(tmplist, newclient); lxc_list_add_elem(tmplist, newclient);
lxc_list_add_tail(&handler->conf->state_clients, tmplist); lxc_list_add_tail(&handler->conf->state_clients, tmplist);
} else { } else {
free(newclient);
free(tmplist);
return state; return state;
} }
TRACE("Added state client %d to state client list", state_client_fd); TRACE("Added state client %d to state client list", state_client_fd);
move_ptr(newclient);
move_ptr(tmplist);
return MAX_STATE; return MAX_STATE;
} }
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