]> 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>
Sun, 17 Dec 2017 15:29:49 +0000 (16:29 +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 1beafa4923c680b97c8f194e9f12958f264db187..035f52f7ea9077ad1de953cc03344d79818613e5 100644 (file)
@@ -546,14 +546,20 @@ 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;
 }
 
index beb12204832b3749a51e90496108aaed19c559fa..466c6350e630efc0136a06bcbf728c2b6fa2bd24 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) {