aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dlfcn.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/dlfcn.c b/src/dlfcn.c
index d52d736..be66cac 100644
--- a/src/dlfcn.c
+++ b/src/dlfcn.c
@@ -30,7 +30,6 @@
30#include <crtdbg.h> 30#include <crtdbg.h>
31#endif 31#endif
32#include <windows.h> 32#include <windows.h>
33#include <stdlib.h> /* malloc() and free() */
34#include <string.h> /* strlen() and memcpy() */ 33#include <string.h> /* strlen() and memcpy() */
35 34
36/* Older versions do not have this type */ 35/* Older versions do not have this type */
@@ -105,6 +104,24 @@ __declspec( naked ) static void *_ReturnAddress( void ) { __asm mov eax, [ebp+4]
105#define DLFCN_NOINLINE 104#define DLFCN_NOINLINE
106#endif 105#endif
107 106
107static void *MyAlloc( size_t size )
108{
109#ifdef _DEBUG
110 return malloc( size );
111#else
112 return LocalAlloc( LPTR, size );
113#endif
114}
115
116static void MyFree( void *ptr )
117{
118#ifdef _DEBUG
119 free( ptr );
120#else
121 LocalFree( ptr );
122#endif
123}
124
108/* Note: 125/* Note:
109 * MSDN says these functions are not thread-safe. We make no efforts to have 126 * MSDN says these functions are not thread-safe. We make no efforts to have
110 * any kind of thread safety. 127 * any kind of thread safety.
@@ -149,7 +166,7 @@ static BOOL local_add( HMODULE hModule )
149 166
150 for( pobject = &first_object; pobject->next; pobject = pobject->next ); 167 for( pobject = &first_object; pobject->next; pobject = pobject->next );
151 168
152 nobject = (local_object *) malloc( sizeof( local_object ) ); 169 nobject = (local_object *) MyAlloc( sizeof( local_object ) );
153 170
154 if( !nobject ) 171 if( !nobject )
155 return FALSE; 172 return FALSE;
@@ -179,7 +196,7 @@ static void local_rem( HMODULE hModule )
179 if( pobject->previous ) 196 if( pobject->previous )
180 pobject->previous->next = pobject->next; 197 pobject->previous->next = pobject->next;
181 198
182 free( pobject ); 199 MyFree( pobject );
183} 200}
184 201
185/* POSIX says dlerror( ) doesn't have to be thread-safe, so we use one 202/* POSIX says dlerror( ) doesn't have to be thread-safe, so we use one
@@ -568,7 +585,7 @@ void *dlsym( void *handle, const char *name )
568 */ 585 */
569 if( MyEnumProcessModules( hCurrentProc, NULL, 0, &dwSize ) != 0 ) 586 if( MyEnumProcessModules( hCurrentProc, NULL, 0, &dwSize ) != 0 )
570 { 587 {
571 modules = (HMODULE *) malloc( dwSize ); 588 modules = (HMODULE *) MyAlloc( dwSize );
572 if( modules ) 589 if( modules )
573 { 590 {
574 if( MyEnumProcessModules( hCurrentProc, modules, dwSize, &cbNeeded ) != 0 && dwSize == cbNeeded ) 591 if( MyEnumProcessModules( hCurrentProc, modules, dwSize, &cbNeeded ) != 0 && dwSize == cbNeeded )
@@ -587,13 +604,13 @@ void *dlsym( void *handle, const char *name )
587 symbol = GetProcAddress( modules[i], name ); 604 symbol = GetProcAddress( modules[i], name );
588 if( symbol != NULL ) 605 if( symbol != NULL )
589 { 606 {
590 free( modules ); 607 MyFree( modules );
591 goto end; 608 goto end;
592 } 609 }
593 } 610 }
594 611
595 } 612 }
596 free( modules ); 613 MyFree( modules );
597 } 614 }
598 else 615 else
599 { 616 {