From 0104678c798aabcd1935d736118d87a1358e14ec Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 2 Feb 2014 13:45:35 +0000 Subject: tool_operate: Moved memory tracking initialisation into tool_main --- src/tool_main.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/tool_main.c') diff --git a/src/tool_main.c b/src/tool_main.c index fe0768747..5e58aff1d 100644 --- a/src/tool_main.c +++ b/src/tool_main.c @@ -82,6 +82,38 @@ static void main_checkfds(void) #endif } +#ifdef CURLDEBUG +void memory_tracking_init(void) +{ + char *env; + /* if CURL_MEMDEBUG is set, this starts memory tracking message logging */ + env = curlx_getenv("CURL_MEMDEBUG"); + if(env) { + /* use the value as file name */ + char fname[CURL_MT_LOGFNAME_BUFSIZE]; + if(strlen(env) >= CURL_MT_LOGFNAME_BUFSIZE) + env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0'; + strcpy(fname, env); + curl_free(env); + curl_memdebug(fname); + /* this weird stuff here is to make curl_free() get called + before curl_memdebug() as otherwise memory tracking will + log a free() without an alloc! */ + } + /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */ + env = curlx_getenv("CURL_MEMLIMIT"); + if(env) { + char *endptr; + long num = strtol(env, &endptr, 10); + if((endptr != env) && (endptr == env + strlen(env)) && (num > 0)) + curl_memlimit(num); + curl_free(env); + } +} +#else +# define memory_tracking_init() Curl_nop_stmt +#endif + /* ** curl tool main function. */ @@ -99,6 +131,10 @@ int main(int argc, char *argv[]) (void)signal(SIGPIPE, SIG_IGN); #endif + /* Initialize memory tracking */ + memory_tracking_init(); + + /* Start our curl operation */ res = operate(&config, argc, argv); #ifdef __SYMBIAN32__ -- cgit v1.2.3