]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
memdebug: drop dynamic allocation from `curl_dbg_log()`
authorViktor Szakats <commit@vsz.me>
Sun, 16 Mar 2025 18:45:58 +0000 (19:45 +0100)
committerViktor Szakats <commit@vsz.me>
Mon, 24 Mar 2025 09:22:58 +0000 (10:22 +0100)
Closes #16745

lib/memdebug.c

index 894da9db0eff3e6908eddb5a7f418ad413447c25..58e4614f5f0a2b9896299f0b62634c5c3907ec53 100644 (file)
@@ -433,33 +433,25 @@ int curl_dbg_fclose(FILE *file, int line, const char *source)
   return res;
 }
 
-#define LOGLINE_BUFSIZE  1024
-
 /* this does the writing to the memory tracking log file */
 void curl_dbg_log(const char *format, ...)
 {
-  char *buf;
+  char buf[1024];
   int nchars;
   va_list ap;
 
   if(!curl_dbg_logfile)
     return;
 
-  buf = (Curl_cmalloc)(LOGLINE_BUFSIZE);
-  if(!buf)
-    return;
-
   va_start(ap, format);
-  nchars = mvsnprintf(buf, LOGLINE_BUFSIZE, format, ap);
+  nchars = mvsnprintf(buf, sizeof(buf), format, ap);
   va_end(ap);
 
-  if(nchars > LOGLINE_BUFSIZE - 1)
-    nchars = LOGLINE_BUFSIZE - 1;
+  if(nchars > (int)sizeof(buf) - 1)
+    nchars = (int)sizeof(buf) - 1;
 
   if(nchars > 0)
     fwrite(buf, 1, (size_t)nchars, curl_dbg_logfile);
-
-  (Curl_cfree)(buf);
 }
 
 #endif /* CURLDEBUG */