]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
libtest/first: stop defining MEMDEBUG_NODEFINES
authorDaniel Stenberg <daniel@haxx.se>
Sat, 5 Apr 2025 15:53:02 +0000 (17:53 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 5 Apr 2025 16:20:22 +0000 (18:20 +0200)
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

tests/libtest/first.c

index bf1d80f873a1cee979469fa686efa6813bc3d877..d170b05fa27c9f0eb4e3ebf1f269a0a71a7f6b60 100644 (file)
 #  include <locale.h> /* 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