Jeffrey Morlan <mrnobo1024@yahoo.com>

- 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
This commit is contained in:
Aleksey Bragin 2008-06-20 19:00:37 +00:00
parent b22a7f63e8
commit a04bcca3a3
2 changed files with 33 additions and 1 deletions

View file

@ -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;
}

View file

@ -3,6 +3,6 @@
<module name="wine" type="staticlibrary">
<define name="_DISABLE_TIDENTS" />
<file>config.c</file>
<file>debug.c</file>
<file>debug_ros.c</file>
<file>string.c</file>
</module>