From 91be8bf0a1a194c4f8ff933e03f779fd21fa78f7 Mon Sep 17 00:00:00 2001 From: Oleg Dubinskiy Date: Sat, 6 Apr 2024 17:46:11 +0200 Subject: [PATCH] [MSVCRT20][MSVCRT40] Fix heap initialization (#6713) CORE-19505 Fixes CORE-19505 'game "Hover!" from rapps does not start anymore' It failed showing a msgbox "There was an error allocating memory in Hover!" the regression was introduced by 0.4.15-dev-5602-g c47506a5f4675b4c2248e9874ed32072d787a8bb Add missing heap initialization in DllMain entrypoints of msvcrt20.dll and msvcrt40.dll, similarly to as it is done in msvcrt.dll (CRT). The msvcrt.dll (CRT) initialization code was updated properly during the last winesync, accordingly to the new changes, but msvcrt20.dll/msvcrt40.dll one was not. So update it too. This fixes the crash of HOVER 1.0 game from Rapps when it tries to allocate a dynamical memory from the unitialized heap via malloc() function exported from our msvcrt20.dll. --- dll/win32/msvcrt20/msvcrt20.c | 5 +++++ dll/win32/msvcrt40/msvcrt40.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/dll/win32/msvcrt20/msvcrt20.c b/dll/win32/msvcrt20/msvcrt20.c index 0bda9aa8172..8d1a6eca4e8 100644 --- a/dll/win32/msvcrt20/msvcrt20.c +++ b/dll/win32/msvcrt20/msvcrt20.c @@ -53,6 +53,8 @@ extern char** __initenv; /* pointer to initial environment block */ extern wchar_t** _wenviron; /* pointer to environment block */ extern wchar_t** __winitenv; /* pointer to initial environment block */ + +extern BOOL msvcrt_init_heap(void); extern void CDECL __getmainargs(int *argc, char** *argv, char** *envp, int expand_wildcards, int *new_mode); extern void CDECL __wgetmainargs(int *argc, WCHAR** *wargv, WCHAR** *wenvp, @@ -82,6 +84,9 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) if (!msvcrt_init_tls()) return FALSE; + if (!msvcrt_init_heap()) + return FALSE; + if (BlockEnvToEnvironA() < 0) return FALSE; diff --git a/dll/win32/msvcrt40/msvcrt40.c b/dll/win32/msvcrt40/msvcrt40.c index 1509cf3cd4a..3c015094782 100644 --- a/dll/win32/msvcrt40/msvcrt40.c +++ b/dll/win32/msvcrt40/msvcrt40.c @@ -54,6 +54,8 @@ extern char** __initenv; /* pointer to initial environment block */ extern wchar_t** _wenviron; /* pointer to environment block */ extern wchar_t** __winitenv; /* pointer to initial environment block */ +extern BOOL msvcrt_init_heap(void); + /* LIBRARY ENTRY POINT ********************************************************/ BOOL @@ -78,6 +80,9 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved) if (!msvcrt_init_tls()) return FALSE; + if (!msvcrt_init_heap()) + return FALSE; + if (BlockEnvToEnvironA() < 0) return FALSE;