]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
coverity: #1425879
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 9 Dec 2017 18:00:37 +0000 (19:00 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 11 Dec 2017 11:02:37 +0000 (12:02 +0100)
do not double close file descriptor

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/console.c
src/lxc/tools/lxc_attach.c

index c8775de6c0b1e642d0bc5691aad0007e1178d946..7a7678d188e68a4bf26478ca2890d6e3548cf0dd 100644 (file)
@@ -588,15 +588,22 @@ void lxc_console_delete(struct lxc_console *console)
        free(console->tios);
        console->tios = NULL;
 
-       close(console->peer);
-       close(console->master);
-       close(console->slave);
-       if (console->log_fd >= 0)
-               close(console->log_fd);
+       if (console->peer >= 0)
+               close(console->peer);
        console->peer = -1;
+
+       if (console->master >= 0)
+               close(console->master);
        console->master = -1;
+
+       if (console->slave >= 0)
+               close(console->slave);
        console->slave = -1;
+
+       if (console->log_fd >= 0)
+               close(console->log_fd);
        console->log_fd = -1;
+
        if (console->buffer_log_file_fd >= 0)
                close(console->buffer_log_file_fd);
        console->buffer_log_file_fd = -1;
index 47a4f0c2772f2a5f2536c3568940b4c5f2148f8a..ccd1787dff350519f969e7ac0d1f82f088870c7f 100644 (file)
@@ -348,6 +348,7 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
        if (c->attach(c, get_pty_on_host_callback, wrap, wrap->options, pid) < 0)
                goto err1;
        close(conf->console.slave); /* Close slave side. */
+       conf->console.slave = -1;
 
        ret = lxc_mainloop_open(&descr);
        if (ret) {