aboutsummaryrefslogtreecommitdiff
path: root/lib/memdebug.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2006-11-05 12:42:50 +0000
committerYang Tse <yangsita@gmail.com>2006-11-05 12:42:50 +0000
commit1bcbe89802776fa735d1f50deb921add4a33b766 (patch)
tree85a91c0d92cfd8dc8ba85a6208f177a14e776e1f /lib/memdebug.c
parentbf57e9bb12c502c828a052e1901349a8c522a617 (diff)
Prevent multiple initialization of memdebug configuration variables.
This was possible on debug c-ares enabled builds when both CURL_MEMDEBUG and CARES_MEMDEBUG environment variables were set. Leading to a file handle leak even when both variables had the same value, and wierd test suite results when different.
Diffstat (limited to 'lib/memdebug.c')
-rw-r--r--lib/memdebug.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/memdebug.c b/lib/memdebug.c
index 2b6c55c3b..a8cca44cb 100644
--- a/lib/memdebug.c
+++ b/lib/memdebug.c
@@ -61,25 +61,29 @@ struct memdebug {
*/
#define logfile curl_debuglogfile
-FILE *curl_debuglogfile;
-static bool memlimit; /* enable memory limit */
-static long memsize; /* set number of mallocs allowed */
+FILE *curl_debuglogfile = NULL;
+static bool memlimit = FALSE; /* enable memory limit */
+static long memsize = 0; /* set number of mallocs allowed */
/* this sets the log file name */
void curl_memdebug(const char *logname)
{
- if(logname)
- logfile = fopen(logname, "w");
- else
- logfile = stderr;
+ if (!logfile) {
+ if(logname)
+ logfile = fopen(logname, "w");
+ else
+ logfile = stderr;
+ }
}
/* This function sets the number of malloc() calls that should return
successfully! */
void curl_memlimit(long limit)
{
- memlimit = TRUE;
- memsize = limit;
+ if (!memlimit) {
+ memlimit = TRUE;
+ memsize = limit;
+ }
}
/* returns TRUE if this isn't allowed! */