Since the NSS lib closes the socket the memory tracking system wrongly gets a
false positive on a leaked socket, so this introduces a way to tell the system
that the socket is indeed closed without explicitly closing it!
diff --git a/lib/memdebug.c b/lib/memdebug.c
index 3a0cf71..ea3eb85 100644
--- a/lib/memdebug.c
+++ b/lib/memdebug.c
@@ -263,13 +263,19 @@
   return sockfd;
 }
 
+/* separate function to allow libcurl to mark a "faked" close */
+int curl_mark_sclose(int sockfd, int line, const char *source)
+{
+  if(logfile)
+    fprintf(logfile, "FD %s:%d sclose(%d)\n",
+            source, line, sockfd);
+}
+
 /* this is our own defined way to close sockets on *ALL* platforms */
 int curl_sclose(int sockfd, int line, const char *source)
 {
   int res=sclose(sockfd);
-  if(logfile)
-    fprintf(logfile, "FD %s:%d sclose(%d)\n",
-            source, line, sockfd);
+  curl_mark_sclose(sockfd, line, source);
   return res;
 }
 
diff --git a/lib/memdebug.h b/lib/memdebug.h
index 6e7e8d7..57e89b1 100644
--- a/lib/memdebug.h
+++ b/lib/memdebug.h
@@ -57,6 +57,7 @@
 
 /* file descriptor manipulators */
 CURL_EXTERN int curl_socket(int domain, int type, int protocol, int line , const char *);
+CURL_EXTERN int curl_mark_sclose(int sockfd, int, const char *source);
 CURL_EXTERN int curl_sclose(int sockfd, int, const char *source);
 CURL_EXTERN int curl_accept(int s, void *addr, void *addrlen,
                             int line, const char *source);
@@ -117,6 +118,8 @@
 #undef sclose
 #define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
 
+#define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__)
+
 #undef fopen
 #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
 #undef fdopen
@@ -127,3 +130,7 @@
 
 #endif /* _CURL_MEMDEBUG_H */
 #endif /* CURLDEBUG */
+
+#ifndef fake_sclose
+#define fake_sclose(x)
+#endif
diff --git a/lib/nss.c b/lib/nss.c
index 866b1d0..7408585 100644
--- a/lib/nss.c
+++ b/lib/nss.c
@@ -930,6 +930,7 @@
 
     /* NSS closes the socket we previously handed to it, so we must mark it
        as closed to avoid double close */
+    fake_sclose(conn->sock[sockindex]);
     conn->sock[sockindex] = CURL_SOCKET_BAD;
     if(connssl->client_nickname != NULL) {
       free(connssl->client_nickname);