From ecbb5a4f6796cbb9d370ab881155ed1b29142c8f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 16 Sep 2020 22:16:10 +0200 Subject: [PATCH] nspawn: fix fd leak on failure path (cherry picked from commit 2fef50cd9eee59cea6145639f6bd464939fac624) (cherry picked from commit f2763ff6cd9385e82171e17ed83a7698c7f561fd) (cherry picked from commit 8bc7ff600f065106eed3cad5689ad5db6ab68583) --- src/nspawn/nspawn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d9a8c50718..b4cdf9d16f 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2105,7 +2105,7 @@ static int setup_pts(const char *dest) { } static int setup_stdio_as_dev_console(void) { - int terminal; + _cleanup_close_ int terminal = -1; int r; terminal = open_terminal("/dev/console", O_RDWR); @@ -2120,6 +2120,7 @@ static int setup_stdio_as_dev_console(void) { /* invalidates 'terminal' on success and failure */ r = rearrange_stdio(terminal, terminal, terminal); + TAKE_FD(terminal); if (r < 0) return log_error_errno(r, "Failed to move console to stdin/stdout/stderr: %m"); -- 2.25.1