]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: fix fd leak
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 9 Mar 2020 09:05:25 +0000 (10:05 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 9 Mar 2020 20:47:46 +0000 (21:47 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c

index e9030e3482500caacc61a19c6f60c43e01c49902..4930397b4cc2ee83b7c3e2e62e81b4fc22423257 100644 (file)
@@ -431,6 +431,13 @@ static char *lxc_attach_getpwshell(uid_t uid)
        close(pipes[1]);
 
        pipe_f = fdopen(pipes[0], "r");
+       if (!pipe_f) {
+               close(pipes[0]);
+               goto reap_child;
+       }
+       /* Transfer ownership of pipes[0] to pipe_f. */
+       move_fd(pipes[0]);
+
        while (getline(&line, &line_bufsz, pipe_f) != -1) {
                int i;
                long value;
@@ -493,6 +500,7 @@ static char *lxc_attach_getpwshell(uid_t uid)
                found = true;
        }
 
+reap_child:
        ret = wait_for_pid(pid);
        if (ret < 0) {
                free(result);