]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: fix fd leak on failure path
authorLennart Poettering <lennart@poettering.net>
Wed, 16 Sep 2020 20:16:10 +0000 (22:16 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 20 Sep 2020 10:51:32 +0000 (12:51 +0200)
(cherry picked from commit 2fef50cd9eee59cea6145639f6bd464939fac624)
(cherry picked from commit f2763ff6cd9385e82171e17ed83a7698c7f561fd)
(cherry picked from commit 8bc7ff600f065106eed3cad5689ad5db6ab68583)
(cherry picked from commit ecbb5a4f6796cbb9d370ab881155ed1b29142c8f)

src/nspawn/nspawn.c

index a9cb74cb7f6bb68259d2cd253e494f1cab19e20c..17bb1c5947d0c945de8d6578227ea4985d282b3c 100644 (file)
@@ -2083,7 +2083,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);
@@ -2098,6 +2098,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");