From: Michael Tremer Date: Sat, 15 Feb 2025 11:39:27 +0000 (+0000) Subject: pty: Close the file descriptor of the console X-Git-Tag: 0.9.30~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d843cbadf33899eb0d6eff6f3dd40bac6d981f80;p=pakfire.git pty: Close the file descriptor of the console This file descriptor was otherwise just leaked. Signed-off-by: Michael Tremer --- 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; } /*