From: Daniel Stenberg Date: Sat, 5 Apr 2025 15:53:02 +0000 (+0200) Subject: libtest/first: stop defining MEMDEBUG_NODEFINES X-Git-Tag: curl-8_14_0~357 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=3454844f36efb102afb5e775975b9dbf1544b54c;p=thirdparty%2Fcurl.git libtest/first: stop defining MEMDEBUG_NODEFINES It causes problems in unity builds, in particular when this file is used for unit tests. Bonus: switch to plain getenv() instead of curl_getenv() to avoid extra malloc/free rounds. Closes #16978 --- diff --git a/tests/libtest/first.c b/tests/libtest/first.c index bf1d80f873..d170b05fa2 100644 --- a/tests/libtest/first.c +++ b/tests/libtest/first.c @@ -28,13 +28,8 @@ # include /* for setlocale() */ #endif -#ifdef CURLDEBUG -# define MEMDEBUG_NODEFINES -# include "memdebug.h" -#endif - +#include "memdebug.h" #include "timediff.h" - #include "tool_binmode.h" int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc, @@ -88,27 +83,18 @@ static void memory_tracking_init(void) { char *env; /* if CURL_MEMDEBUG is set, this starts memory tracking message logging */ - env = curl_getenv("CURL_MEMDEBUG"); + env = 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_dbg_memdebug(fname); - /* this weird stuff here is to make curl_free() get called before - curl_dbg_memdebug() as otherwise memory tracking will log a free() - without an alloc! */ + curl_dbg_memdebug(env); } /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */ - env = curl_getenv("CURL_MEMLIMIT"); + env = getenv("CURL_MEMLIMIT"); if(env) { char *endptr; long num = strtol(env, &endptr, 10); if((endptr != env) && (endptr == env + strlen(env)) && (num > 0)) curl_dbg_memlimit(num); - curl_free(env); } } #else