From d843cbadf33899eb0d6eff6f3dd40bac6d981f80 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 15 Feb 2025 11:39:27 +0000 Subject: [PATCH] pty: Close the file descriptor of the console This file descriptor was otherwise just leaked. Signed-off-by: Michael Tremer --- src/pakfire/pty.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/pakfire/pty.c b/src/pakfire/pty.c index 85226676..43dc7c29 100644 --- a/src/pakfire/pty.c +++ b/src/pakfire/pty.c @@ -1341,7 +1341,8 @@ static int pakfire_pty_setup_terminal(struct pakfire_pty* pty) { fd = open("/dev/console", O_RDWR|O_NOCTTY); if (fd < 0) { ERROR(pty->ctx, "Failed to open a new terminal: %s\n", strerror(errno)); - return -errno; + r = -errno; + goto ERROR; } DEBUG(pty->ctx, "Opened a new terminal %d\n", fd); @@ -1350,24 +1351,31 @@ static int pakfire_pty_setup_terminal(struct pakfire_pty* pty) { r = dup2(fd, STDIN_FILENO); if (r < 0) { ERROR(pty->ctx, "Failed to open standard input: %s\n", strerror(errno)); - return -errno; + r = -errno; + goto ERROR; } // Connect the new terminal to standard output r = dup2(fd, STDOUT_FILENO); if (r < 0) { ERROR(pty->ctx, "Failed to open standard output: %s\n", strerror(errno)); - return -errno; + r = -errno; + goto ERROR; } // Connect the new terminal to standard error r = dup2(fd, STDERR_FILENO); if (r < 0) { ERROR(pty->ctx, "Failed to open standard error: %s\n", strerror(errno)); - return -errno; + r = -errno; + goto ERROR; } - return 0; +ERROR: + if (fd >= 0) + close(fd); + + return r; } /* -- 2.39.5