]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands_utils: fix socket leak in when adding state client
authorMatthias Hardt <matthias.hardt@gmail.com>
Mon, 9 Mar 2020 14:53:11 +0000 (15:53 +0100)
committerMatthias Hardt <matthias.hardt@gmail.com>
Mon, 9 Mar 2020 14:56:36 +0000 (15:56 +0100)
If lxc_add_state_client() is called with the container already being in
the desired state the client fd will never be closed and is leaking.
This due to setting stay_connected in lxc_cmd for
LXC_CMD_ADD_STATE_CLIENT. If the desired state isn't already achieved
the client fd will later be closed by calling lxc_cmd_fd_cleanup() but
in the other case the client configuration isn't added to the handlers
state clients. So the client fd has to be closed explicitely.

This is simply tested by starting container A and calling lxc-wait -n A
-s RUNNING.

Signed-off-by: Matthias Hardt <matthias.hardt@gmail.com>
src/lxc/commands_utils.c

index 67edc4ca95f11c9f7d67ca93f065b9cb285be189..a8f1e1705516e56fe2b994628110f8cc801e129e 100644 (file)
@@ -195,6 +195,7 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
                lxc_list_add_elem(tmplist, newclient);
                lxc_list_add_tail(&handler->conf->state_clients, tmplist);
        } else {
+               close(state_client_fd);
                return state;
        }