Commit c27022355a47af61bf4be7188d8e5637cf0f9aac

Andreas Smas 2017-01-20T23:14:19

Use SOCK_CLOEXEC when creating sockets

diff --git a/src/posix.h b/src/posix.h
index d26371b..b48b410 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -59,6 +59,9 @@
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 0
 #endif
+#ifndef SOCK_CLOEXEC
+#define SOCK_CLOEXEC 0
+#endif
 
 /* access() mode parameter #defines	*/
 #ifndef F_OK
diff --git a/src/socket_stream.c b/src/socket_stream.c
index c0a1684..96bd2b9 100644
--- a/src/socket_stream.c
+++ b/src/socket_stream.c
@@ -104,7 +104,7 @@ int socket_connect(git_stream *stream)
 	}
 
 	for (p = info; p != NULL; p = p->ai_next) {
-		s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
+		s = socket(p->ai_family, p->ai_socktype | SOCK_CLOEXEC, p->ai_protocol);
 
 		if (s == INVALID_SOCKET)
 			continue;