On Sun, 18 Oct 2009, Daniel Stenberg wrote:
The only decent fix for this false positive - I think - is to make some kind
of fake call to the socket close for the sake of the memory debugging.
Okey, I hacked up a quick patch to show you what I meant.
You think this works fine enough?
--
/ daniel.haxx.se
Index: memdebug.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/memdebug.c,v
retrieving revision 1.63
diff -u -p -r1.63 memdebug.c
--- memdebug.c 2 May 2009 02:37:34 -0000 1.63
+++ memdebug.c 19 Oct 2009 22:09:34 -0000
@@ -263,13 +263,19 @@ int curl_accept(int s, void *saddr, void
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: memdebug.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/memdebug.h,v
retrieving revision 1.39
diff -u -p -r1.39 memdebug.h
--- memdebug.h 15 Jul 2009 01:10:18 -0000 1.39
+++ memdebug.h 19 Oct 2009 22:09:34 -0000
@@ -57,6 +57,7 @@ CURL_EXTERN void curl_memlimit(long limi
/* 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,
#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,
#endif /* _CURL_MEMDEBUG_H */
#endif /* CURLDEBUG */
+
+#ifndef fake_sclose
+#define fake_sclose(x)
+#endif
Index: nss.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/nss.c,v
retrieving revision 1.61
diff -u -p -r1.61 nss.c
--- nss.c 18 Oct 2009 00:10:13 -0000 1.61
+++ nss.c 19 Oct 2009 22:09:35 -0000
@@ -930,6 +930,7 @@ void Curl_nss_close(struct connectdata *
/* 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);
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html