]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Since the NSS lib closes the socket the memory tracking system wrongly gets a
authorDaniel Stenberg <daniel@haxx.se>
Wed, 28 Oct 2009 20:30:23 +0000 (20:30 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 28 Oct 2009 20:30:23 +0000 (20:30 +0000)
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!

lib/memdebug.c
lib/memdebug.h
lib/nss.c

index 3a0cf71537b770cf8deaa7087bb663282daf4d2c..ea3eb85592b3531dc7636d8eea658006087caa03 100644 (file)
@@ -263,13 +263,19 @@ int curl_accept(int s, void *saddr, void *saddrlen,
   return sockfd;
 }
 
-/* this is our own defined way to close sockets on *ALL* platforms */
-int curl_sclose(int sockfd, int line, const char *source)
+/* separate function to allow libcurl to mark a "faked" close */
+int curl_mark_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);
+}
+
+/* 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);
+  curl_mark_sclose(sockfd, line, source);
   return res;
 }
 
index 6e7e8d7f227b2913ce0f24f4c1bb5ab79d7799a5..57e89b1d44f0eec847bc947f3707076949f69a35 100644 (file)
@@ -57,6 +57,7 @@ CURL_EXTERN void curl_memlimit(long limit);
 
 /* 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 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
 #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 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
 
 #endif /* _CURL_MEMDEBUG_H */
 #endif /* CURLDEBUG */
+
+#ifndef fake_sclose
+#define fake_sclose(x)
+#endif
index 866b1d0c8f57e3ffdcd2943f4a74fa37568590a4..7408585da7fe35d50636894d81b563eef2e9e95e 100644 (file)
--- a/lib/nss.c
+++ b/lib/nss.c
@@ -930,6 +930,7 @@ void Curl_nss_close(struct connectdata *conn, int sockindex)
 
     /* 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);