From: Christian Brauner Date: Mon, 9 Mar 2020 09:05:25 +0000 (+0100) Subject: attach: fix fd leak X-Git-Tag: lxc-4.0.0~42^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf4026f1f5ce8583d05907eecf64e396d75c78a8;p=thirdparty%2Flxc.git attach: fix fd leak Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index e9030e348..4930397b4 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -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);