Ecore con local: properly clean up fd on error. 29/82229/2
authorTom Hacohen <tom@stosb.com>
Fri, 5 Feb 2016 11:48:36 +0000 (11:48 +0000)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 5 Aug 2016 04:51:10 +0000 (21:51 -0700)
This wasn't done correctly in the previous commit. First of all, the
order of cleanup was wrong, the cleanup area should only be called if
failures occurred after the fd allocation, not before. Also, fd should
be reinitialised to -1 once we close the socket.

Change-Id: I96edd3c4685300e4ec8e25e55aa8a17774700eb5
Signed-off-by: Awadhesh Singh <awadhesh1.s@samsung.com>
src/lib/ecore_con/ecore_con_local.c

index e514d44..dc81334 100644 (file)
@@ -463,16 +463,16 @@ start:
      goto error_umask;
 
    if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
-     goto error_umask;
+     goto error_fd;
 
    if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
-     goto error_umask;
+     goto error_fd;
 
    lin.l_onoff = 1;
    lin.l_linger = 0;
    if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
                   sizeof(struct linger)) < 0)
-     goto error_umask;
+     goto error_fd;
 
    if (bind(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
      {
@@ -488,13 +488,13 @@ start:
              else
                {
                   ERR("Local socket '%s' removal failed: %s", buf, strerror(errno));
-                  goto error_umask;
+                  goto error_fd;
                }
           }
      }
 
    if (listen(svr->fd, 4096) < 0)
-     goto error_umask;
+     goto error_fd;
 
 #ifdef HAVE_SYSTEMD
 fd_ready:
@@ -512,6 +512,9 @@ fd_ready:
 
    return 1;
 
+error_fd:
+   close(svr->fd);
+   svr->fd = -1;
 error_umask:
    umask(pmode);
 error: