From a04bcca3a3bc072b89ca756fd1fe87b64be3042e Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Fri, 20 Jun 2008 19:00:37 +0000 Subject: [PATCH] Jeffrey Morlan - Wrap libwine's memory allocations, avoiding msvcrt imports in kernel32 - The cause is that libwine/debug.c uses functions (malloc, free, realloc, _strdup) which are only present in a complete CRT, creating imports from msvcrt.dll in any module that uses it, including kernel32.dll. Since kernel32 is currently importing from msvcrt, kernel32 gets DLL_PROCESS_DETACHed first, creating a problem for msvcrt's DLL_PROCESS_DETACH which, as a result of a recent bugfix, now uses kernel32 functions that depend on the resources that were freed. - Fix this by implementing those 4 functions as wrappers around the Local* APIs, in order to avoid the problematic imports. See issue #3373 for more details. svn path=/trunk/; revision=34037 --- reactos/lib/3rdparty/libwine/debug_ros.c | 32 +++++++++++++++++++++ reactos/lib/3rdparty/libwine/libwine.rbuild | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 reactos/lib/3rdparty/libwine/debug_ros.c diff --git a/reactos/lib/3rdparty/libwine/debug_ros.c b/reactos/lib/3rdparty/libwine/debug_ros.c new file mode 100644 index 00000000000..5175ddda6cc --- /dev/null +++ b/reactos/lib/3rdparty/libwine/debug_ros.c @@ -0,0 +1,32 @@ +/* The use of these four functions was creating unwanted imports + * from msvcrt.dll in kernel32.dll. */ + +#define malloc libwine_malloc +#define free libwine_free +#define realloc libwine_realloc +#define _strdup libwine__strdup + +#include "debug.c" + +void *malloc(size_t size) +{ + return LocalAlloc(0, size); +} + +void free(void *ptr) +{ + LocalFree(ptr); +} + +void *realloc(void *ptr, size_t size) +{ + if (ptr == NULL) return malloc(size); + return LocalReAlloc(ptr, size, LMEM_MOVEABLE); +} + +char *_strdup(const char *str) +{ + char *newstr = malloc(strlen(str) + 1); + if (newstr) strcpy(newstr, str); + return newstr; +} diff --git a/reactos/lib/3rdparty/libwine/libwine.rbuild b/reactos/lib/3rdparty/libwine/libwine.rbuild index 0a0e4869324..fc202456d03 100644 --- a/reactos/lib/3rdparty/libwine/libwine.rbuild +++ b/reactos/lib/3rdparty/libwine/libwine.rbuild @@ -3,6 +3,6 @@ config.c - debug.c + debug_ros.c string.c