]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curlx: use curlx allocators in non-memdebug builds (Windows)
authorViktor Szakats <commit@vsz.me>
Mon, 1 Dec 2025 14:25:26 +0000 (15:25 +0100)
committerViktor Szakats <commit@vsz.me>
Mon, 1 Dec 2025 18:42:56 +0000 (19:42 +0100)
To limit raw allocators to `CURLDEBUG` (memdebug/TrackMemory) Windows
UNICODE builds.

Closes #19788

lib/curlx/fopen.c
lib/curlx/multibyte.c
lib/curlx/multibyte.h

index caf4978af1636e92f9243a528538c55ba7c10ac6..1838b7de8b8ca564e4db84dc2810765db9fcf1a4 100644 (file)
@@ -100,8 +100,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
     goto cleanup;
   if(!needed || needed >= max_path_len)
     goto cleanup;
-  /* !checksrc! disable BANNEDFUNC 1 */
-  ibuf = malloc(needed * sizeof(wchar_t));
+  ibuf = CURLX_MALLOC(needed * sizeof(wchar_t));
   if(!ibuf)
     goto cleanup;
   if(mbstowcs_s(&count, ibuf, needed, in, needed - 1))
@@ -122,8 +121,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
   /* skip paths that are not excessive and do not need modification */
   if(needed <= MAX_PATH)
     goto cleanup;
-  /* !checksrc! disable BANNEDFUNC 1 */
-  fbuf = malloc(needed * sizeof(wchar_t));
+  fbuf = CURLX_MALLOC(needed * sizeof(wchar_t));
   if(!fbuf)
     goto cleanup;
   count = (size_t)GetFullPathNameW(in_w, (DWORD)needed, fbuf, NULL);
@@ -156,19 +154,16 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
       if(needed > max_path_len)
         goto cleanup;
 
-      /* !checksrc! disable BANNEDFUNC 1 */
-      temp = malloc(needed * sizeof(wchar_t));
+      temp = CURLX_MALLOC(needed * sizeof(wchar_t));
       if(!temp)
         goto cleanup;
 
       if(wcsncpy_s(temp, needed, L"\\\\?\\UNC\\", 8)) {
-        /* !checksrc! disable BANNEDFUNC 1 */
-        free(temp);
+        CURLX_FREE(temp);
         goto cleanup;
       }
       if(wcscpy_s(temp + 8, needed, fbuf + 2)) {
-        /* !checksrc! disable BANNEDFUNC 1 */
-        free(temp);
+        CURLX_FREE(temp);
         goto cleanup;
       }
     }
@@ -178,25 +173,21 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
       if(needed > max_path_len)
         goto cleanup;
 
-      /* !checksrc! disable BANNEDFUNC 1 */
-      temp = malloc(needed * sizeof(wchar_t));
+      temp = CURLX_MALLOC(needed * sizeof(wchar_t));
       if(!temp)
         goto cleanup;
 
       if(wcsncpy_s(temp, needed, L"\\\\?\\", 4)) {
-        /* !checksrc! disable BANNEDFUNC 1 */
-        free(temp);
+        CURLX_FREE(temp);
         goto cleanup;
       }
       if(wcscpy_s(temp + 4, needed, fbuf)) {
-        /* !checksrc! disable BANNEDFUNC 1 */
-        free(temp);
+        CURLX_FREE(temp);
         goto cleanup;
       }
     }
 
-    /* !checksrc! disable BANNEDFUNC 1 */
-    free(fbuf);
+    CURLX_FREE(fbuf);
     fbuf = temp;
   }
 
@@ -206,8 +197,7 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
     goto cleanup;
   if(!needed || needed >= max_path_len)
     goto cleanup;
-  /* !checksrc! disable BANNEDFUNC 1 */
-  obuf = malloc(needed);
+  obuf = CURLX_MALLOC(needed);
   if(!obuf)
     goto cleanup;
   if(wcstombs_s(&count, obuf, needed, fbuf, needed - 1))
@@ -222,12 +212,10 @@ static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
 #endif
 
 cleanup:
-  /* !checksrc! disable BANNEDFUNC 1 */
-  free(fbuf);
+  CURLX_FREE(fbuf);
 #ifndef _UNICODE
-  /* !checksrc! disable BANNEDFUNC 2 */
-  free(ibuf);
-  free(obuf);
+  CURLX_FREE(ibuf);
+  CURLX_FREE(obuf);
 #endif
   return *out ? true : false;
 }
@@ -269,8 +257,7 @@ int curlx_win32_open(const char *filename, int oflag, ...)
   errno = _sopen_s(&result, target, oflag, _SH_DENYNO, pmode);
 #endif
 
-  /* !checksrc! disable BANNEDFUNC 1 */
-  free(fixed);
+  CURLX_FREE(fixed);
   return result;
 }
 
@@ -303,8 +290,7 @@ FILE *curlx_win32_fopen(const char *filename, const char *mode)
   errno = fopen_s(&result, target, mode);
 #endif
 
-  /* !checksrc! disable BANNEDFUNC 1 */
-  free(fixed);
+  CURLX_FREE(fixed);
   return result;
 }
 
@@ -342,8 +328,7 @@ FILE *curlx_win32_freopen(const char *filename, const char *mode, FILE *fp)
   errno = freopen_s(&result, target, mode, fp);
 #endif
 
-  /* !checksrc! disable BANNEDFUNC 1 */
-  free(fixed);
+  CURLX_FREE(fixed);
   return result;
 }
 
@@ -382,8 +367,7 @@ int curlx_win32_stat(const char *path, struct_stat *buffer)
 #endif
 #endif
 
-  /* !checksrc! disable BANNEDFUNC 1 */
-  free(fixed);
+  CURLX_FREE(fixed);
   return result;
 }
 
index 2583f30870315ce07f79c92180fafd17ee6f1672..fb3b7be3e12057a24cb6da3675017c2798212062 100644 (file)
@@ -45,13 +45,11 @@ wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8)
     int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
                                         str_utf8, -1, NULL, 0);
     if(str_w_len > 0) {
-      /* !checksrc! disable BANNEDFUNC 1 */
-      str_w = malloc(str_w_len * sizeof(wchar_t));
+      str_w = CURLX_MALLOC(str_w_len * sizeof(wchar_t));
       if(str_w) {
         if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
                                str_w_len) == 0) {
-          /* !checksrc! disable BANNEDFUNC 1 */
-          free(str_w);
+          CURLX_FREE(str_w);
           return NULL;
         }
       }
@@ -69,13 +67,11 @@ char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
     int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1,
                                     NULL, 0, NULL, NULL);
     if(bytes > 0) {
-      /* !checksrc! disable BANNEDFUNC 1 */
-      str_utf8 = malloc(bytes);
+      str_utf8 = CURLX_MALLOC(bytes);
       if(str_utf8) {
         if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes,
                                NULL, NULL) == 0) {
-          /* !checksrc! disable BANNEDFUNC 1 */
-          free(str_utf8);
+          CURLX_FREE(str_utf8);
           return NULL;
         }
       }
index fac07c2eeb24eac410fac4a475e98af96ab59b92..3eae4e75bd1f1bfcecc21643b40bba0c8eef6b9c 100644 (file)
  * memory tracker memdebug functions.
  */
 
+#ifdef CURLDEBUG
+#define CURLX_MALLOC(x) malloc(x)
+#define CURLX_FREE(x)   free(x)
+#else
+#define CURLX_MALLOC(x) curlx_malloc(x)
+#define CURLX_FREE(x)   curlx_free(x)
+#endif
+
 /* MultiByte conversions using Windows kernel32 library. */
 wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8);
 char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w);
 
 /* the purpose of this macro is to free() without being traced by memdebug */
-#define curlx_unicodefree(ptr) free(ptr)
+#define curlx_unicodefree(ptr) CURLX_FREE(ptr)
 
 #ifdef UNICODE
 
@@ -65,8 +73,13 @@ typedef union {
 
 #else /* !UNICODE */
 
+#ifdef CURLDEBUG
 #define curlx_convert_UTF8_to_tchar(ptr) _strdup(ptr)
 #define curlx_convert_tchar_to_UTF8(ptr) _strdup(ptr)
+#else
+#define curlx_convert_UTF8_to_tchar(ptr) curlx_strdup(ptr)
+#define curlx_convert_tchar_to_UTF8(ptr) curlx_strdup(ptr)
+#endif
 
 typedef union {
   char                *tchar_ptr;