Commit 1bcbe898 authored by Yang Tse's avatar Yang Tse
Browse files

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.
parent bf57e9bb
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -61,26 +61,30 @@ 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 (!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)
{
  if (!memlimit) {
    memlimit = TRUE;
    memsize = limit;
  }
}

/* returns TRUE if this isn't allowed! */
static bool countcheck(const char *func, int line, const char *source)