]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Close the file descriptor of the console
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Feb 2025 11:39:27 +0000 (11:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Feb 2025 11:39:27 +0000 (11:39 +0000)
This file descriptor was otherwise just leaked.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/pty.c

index 852266768be25d3f2cf6c6093c3d8b2d4eb01ad9..43dc7c292e61485208170e797afef54bd28a4999 100644 (file)
@@ -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;
 }
 
 /*