]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands: improve state client cleanup 3285/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 10 Mar 2020 20:46:25 +0000 (21:46 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 10 Mar 2020 20:46:25 +0000 (21:46 +0100)
Improves: ebbca8529732 ("commands_utils: fix socket leak when adding state client")
Cc: Matthias Hardt <matthias.hardt@gmail.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c

index 4ba8229874d02d4453861f2270d42ad4c1337080..cf3b1ed223e7b4cd1a55418713068f98f927a692 100644 (file)
@@ -873,10 +873,6 @@ static int lxc_cmd_add_state_client_callback(__owns int fd, struct lxc_cmd_req *
        if (ret < 0)
                goto reap_client_fd;
 
-       /* close fd if state is already achieved to avoid leakage */
-       if (rsp.ret != MAX_STATE)
-               close(fd);
-
        return 0;
 
 reap_client_fd:
@@ -1344,12 +1340,20 @@ static void lxc_cmd_fd_cleanup(int fd, struct lxc_handler *handler,
                        close(client->clientfd);
                        free(cur->elem);
                        free(cur);
-                       /* No need to walk the whole list. If we found the state
+                       /*
+                        * No need to walk the whole list. If we found the state
                         * client fd there can't be a second one.
                         */
                        break;
                }
-               break;
+
+               /*
+                * We didn't add the state client to the list. Either because
+                * we failed to allocate memory (unlikely) or because the state
+                * was already reached by the time we were ready to add it. So
+                * fallthrough and clean it up.
+                */
+               __fallthrough;
        default:
                close(fd);
        }