From 570e1173387dba2a173ace8fbab350655599349e Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 1 Feb 2021 22:34:33 +0100 Subject: [PATCH] commands_utils: don't leak memory Signed-off-by: Christian Brauner --- src/lxc/commands_utils.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lxc/commands_utils.c b/src/lxc/commands_utils.c index cba8e9c10..53464ae15 100644 --- a/src/lxc/commands_utils.c +++ b/src/lxc/commands_utils.c @@ -166,7 +166,7 @@ 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; @@ -174,20 +174,19 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler, 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; } -- 2.47.2