--
Best regards,
LIU Hao

From e39bf96903e127093877f3cf4acb074556f7afcb Mon Sep 17 00:00:00 2001
From: LIU Hao <lh_mo...@126.com>
Date: Wed, 30 Oct 2024 01:48:46 +0800
Subject: [PATCH] crt/crtexe: Remove `duplicate_ppstrings()`

This was introduced in a88b7c3354a40b384f6fe4351c67cab85754f9ee without an
explanation about the reason. This function uses `malloc()` to allocate
memory which may be reported as leaks.

The Microsoft UCRT does not do that, so there's no reason to keep this
function with UCRT. For MSVCRT, non-conformance should be expected anyway.

This fixes https://sourceforge.net/p/mingw-w64/bugs/809/.

Signed-off-by: LIU Hao <lh_mo...@126.com>
---
 mingw-w64-crt/crt/crtexe.c | 28 ----------------------------
 1 file changed, 28 deletions(-)

diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index aa0372a52..e5364f7f4 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -69,10 +69,6 @@ extern LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler;
 extern void _pei386_runtime_relocator (void);
 long CALLBACK _gnu_exception_handler (EXCEPTION_POINTERS * exception_data);
 
-#ifdef _UNICODE
-static void duplicate_ppstrings (int ac, _TCHAR ***av);
-#endif
-
 static int __cdecl pre_c_init (void);
 static void __cdecl pre_cpp_init (void);
 _CRTALLOC(".CRT$XIAA") _PIFV __mingw_pcinit = pre_c_init;
@@ -303,11 +299,6 @@ __tmainCRTStartup (void)
     _set_invalid_parameter_handler (__mingw_invalidParameterHandler);
     
     _fpreset ();
-
-#ifdef _UNICODE
-    // Narrow argv is already a local copy so only duplicate the wide version.
-    duplicate_ppstrings (argc, &argv);
-#endif
     __main (); /* C++ initialization. */
 #ifdef _UNICODE
     __winitenv = envp;
@@ -365,25 +356,6 @@ check_managed_app (void)
   return 0;
 }
 
-#ifdef _UNICODE
-static void duplicate_ppstrings (int ac, _TCHAR ***av)
-{
-       _TCHAR **avl;
-       int i;
-       _TCHAR **n = (_TCHAR **) malloc (sizeof (_TCHAR *) * (ac + 1));
-       
-       avl=*av;
-       for (i=0; i < ac; i++)
-         {
-               size_t l = sizeof (_TCHAR) * (_tcslen (avl[i]) + 1);
-               n[i] = (_TCHAR *) malloc (l);
-               memcpy (n[i], avl[i], l);
-         }
-       n[i] = NULL;
-       *av = n;
-}
-#endif
-
 int __cdecl atexit (_PVFV func)
 {
     /*
-- 
2.47.0

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to