]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix another case of bug 8206; patch from flupzor
authorNick Mathewson <nickm@torproject.org>
Mon, 18 Mar 2013 19:44:23 +0000 (15:44 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 18 Mar 2013 19:44:23 +0000 (15:44 -0400)
src/common/compat.c

index 25df9a960c20af60a1d4237be5ff0c74b898f290..4fa9fee42e05afad31851ab6a85889781b9207ec 100644 (file)
@@ -1172,10 +1172,22 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2])
     return -errno;
 
 #if defined(FD_CLOEXEC)
-  if (SOCKET_OK(fd[0]))
-    fcntl(fd[0], F_SETFD, FD_CLOEXEC);
-  if (SOCKET_OK(fd[1]))
-    fcntl(fd[1], F_SETFD, FD_CLOEXEC);
+  if (SOCKET_OK(fd[0])) {
+    r = fcntl(fd[0], F_SETFD, FD_CLOEXEC);
+    if (r == -1) {
+      close(fd[0]);
+      close(fd[1]);
+      return -errno;
+    }
+  }
+  if (SOCKET_OK(fd[1])) {
+    r = fcntl(fd[1], F_SETFD, FD_CLOEXEC);
+    if (r == -1) {
+      close(fd[0]);
+      close(fd[1]);
+      return -errno;
+    }
+  }
 #endif
   goto sockets_ok; /* So that sockets_ok will not be unused. */