]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
coverity: #1426734
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 20 Jan 2018 20:44:50 +0000 (21:44 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 21 Jan 2018 00:54:29 +0000 (01:54 +0100)
do not call close on bad fd

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

index 6dcdd340d86cd6861c87992d357952d4cb918b18..644d2a52f67d2b9aa2bc05a4a223c8ad0e46738d 100644 (file)
@@ -209,7 +209,6 @@ int lxc_monitor_open(const char *lxcpath)
        int fd;
        size_t retry;
        size_t len;
-       int ret = -1;
        int backoff_ms[] = {10, 50, 100};
 
        if (lxc_monitor_sock_name(lxcpath, &addr) < 0)
@@ -218,16 +217,16 @@ int lxc_monitor_open(const char *lxcpath)
        fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (fd < 0) {
                ERROR("Failed to create socket: %s.", strerror(errno));
-               return -errno;
+               return -1;
        }
 
        len = strlen(&addr.sun_path[1]);
        DEBUG("opening monitor socket %s with len %zu", &addr.sun_path[1], len);
        if (len >= sizeof(addr.sun_path) - 1) {
                errno = ENAMETOOLONG;
-               ret = -errno;
                ERROR("name of monitor socket too long (%zu bytes): %s", len, strerror(errno));
-               goto on_error;
+               close(fd);
+               return -1;
        }
 
        for (retry = 0; retry < sizeof(backoff_ms) / sizeof(backoff_ms[0]); retry++) {
@@ -239,16 +238,12 @@ int lxc_monitor_open(const char *lxcpath)
        }
 
        if (fd < 0) {
-               ret = -errno;
                ERROR("Failed to connect to monitor socket: %s.", strerror(errno));
-               goto on_error;
+               close(fd);
+               return -1;
        }
 
        return fd;
-
-on_error:
-       close(fd);
-       return ret;
 }
 
 int lxc_monitor_read_fdset(struct pollfd *fds, nfds_t nfds, struct lxc_msg *msg,