aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2000-12-14 15:56:59 +0000
committerDaniel Stenberg <daniel@haxx.se>2000-12-14 15:56:59 +0000
commitbf43b49a200dace98a5245e782e0831313461b31 (patch)
tree53513978e4fc93377a2c0a06503c43effa0a3780
parent6ad9bd80226dd1468a949b26af265d60f29ac910 (diff)
added socket() / sclose() checks to the memdebug system
-rw-r--r--lib/memdebug.c27
-rw-r--r--lib/memdebug.h13
-rwxr-xr-xmemanalyze.pl29
3 files changed, 69 insertions, 0 deletions
diff --git a/lib/memdebug.c b/lib/memdebug.c
index 8dbad1b73..cbd860ec1 100644
--- a/lib/memdebug.c
+++ b/lib/memdebug.c
@@ -43,6 +43,14 @@
#include <curl/curl.h>
+#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
+#include <winsock.h>
+#else /* some kind of unix */
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#endif
+
#define _MPRINTF_REPLACE
#include <curl/mprintf.h>
#include "urldata.h"
@@ -50,6 +58,8 @@
#include <string.h>
#include <stdlib.h>
+/* DONT include memdebug.h here! */
+
/*
* Note that these debug functions are very simple and they are meant to
* remain so. For advanced analysis, record a log file and write perl scripts
@@ -115,4 +125,21 @@ void curl_dofree(void *ptr, int line, char *source)
source, line, ptr);
}
+int curl_socket(int domain, int type, int protocol, int line, char *source)
+{
+ int sockfd=(socket)(domain, type, protocol);
+ fprintf(logfile?logfile:stderr, "FD %s:%d socket() = %d\n",
+ source, line, sockfd);
+ return sockfd;
+}
+
+/* this is our own defined way to close sockets on *ALL* platforms */
+int curl_sclose(int sockfd, int line, char *source)
+{
+ int res=sclose(sockfd);
+ fprintf(logfile?logfile:stderr, "FD %s:%d sclose(%d)\n",
+ source, line, sockfd);
+ return sockfd;
+}
+
#endif /* MALLOCDEBUG */
diff --git a/lib/memdebug.h b/lib/memdebug.h
index a0d670088..21330a0b2 100644
--- a/lib/memdebug.h
+++ b/lib/memdebug.h
@@ -1,13 +1,26 @@
#ifdef MALLOCDEBUG
+/* memory functions */
void *curl_domalloc(size_t size, int line, char *source);
void *curl_dorealloc(void *ptr, size_t size, int line, char *source);
void curl_dofree(void *ptr, int line, char *source);
char *curl_dostrdup(char *str, int line, char *source);
void curl_memdebug(char *logname);
+/* file descriptor manipulators */
+int curl_socket(int domain, int type, int protocol, int, char *);
+int curl_sclose(int sockfd, int, char *);
+
/* Set this symbol on the command-line, recompile all lib-sources */
#define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
#define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
#define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
#define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
+
+#define socket(domain,type,protocol)\
+ curl_socket(domain,type,protocol,__LINE__,__FILE__)
+
+/* sclose is probably already defined, redefine it! */
+#undef sclose
+#define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
+
#endif
diff --git a/memanalyze.pl b/memanalyze.pl
index 3b706af72..48fff8f27 100755
--- a/memanalyze.pl
+++ b/memanalyze.pl
@@ -72,6 +72,28 @@ while(<STDIN>) {
print "Not recognized input line: $function\n";
}
}
+ # FD url.c:1282 socket() = 5
+ elsif($_ =~ /^FD ([^:]*):(\d*) (.*)/) {
+ # generic match for the filename+linenumber
+ $source = $1;
+ $linenum = $2;
+ $function = $3;
+
+ if($function =~ /socket\(\) = (\d*)/) {
+ $filedes{$1}=1;
+ $getfile{$1}="$source:$linenum";
+ $openfile++;
+ }
+ elsif($function =~ /sclose\((\d*)\)/) {
+ if($filedes{$1} != 1) {
+ print "Close without open: $line\n";
+ }
+ else {
+ $filedes{$1}=0; # closed now
+ $openfile--;
+ }
+ }
+ }
else {
print "Not recognized prefix line: $line\n";
}
@@ -93,3 +115,10 @@ if($totalmem) {
}
}
+if($openfile) {
+ for(keys %filedes) {
+ if($filedes{$_} == 1) {
+ print "Open file descriptor created at ".$getfile{$_}."\n";
+ }
+ }
+}