Merge pull request #62 from pali/master Reduce memory usage by 64K
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
diff --git a/dlfcn.c b/dlfcn.c
index f8af91f..c5d4b3c 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -129,8 +129,7 @@ static void local_rem( HMODULE hModule )
* the limit.
*/
static char error_buffer[65535];
-static char *current_error;
-static char dlerror_buffer[65536];
+static BOOL error_occurred;
static void save_err_str( const char *str )
{
@@ -175,7 +174,7 @@ static void save_err_str( const char *str )
error_buffer[pos-2] = '\0';
}
- current_error = error_buffer;
+ error_occurred = TRUE;
}
static void save_err_ptr_str( const void *ptr )
@@ -214,7 +213,7 @@ void *dlopen( const char *file, int mode )
HMODULE hModule;
UINT uMode;
- current_error = NULL;
+ error_occurred = FALSE;
/* Do not let Windows display the critical-error-handler message box */
uMode = SetErrorMode( SEM_FAILCRITICALERRORS );
@@ -321,7 +320,7 @@ int dlclose( void *handle )
HMODULE hModule = (HMODULE) handle;
BOOL ret;
- current_error = NULL;
+ error_occurred = FALSE;
ret = FreeLibrary( hModule );
@@ -347,7 +346,8 @@ void *dlsym( void *handle, const char *name )
HMODULE hModule;
HANDLE hCurrentProc;
- current_error = NULL;
+ error_occurred = FALSE;
+
symbol = NULL;
hCaller = NULL;
hModule = GetModuleHandle( NULL );
@@ -459,22 +459,16 @@ end:
char *dlerror( void )
{
- char *error_pointer = dlerror_buffer;
-
/* If this is the second consecutive call to dlerror, return NULL */
- if (current_error == NULL)
- {
+ if( !error_occurred )
return NULL;
- }
-
- memcpy(error_pointer, current_error, strlen(current_error) + 1);
/* POSIX says that invoking dlerror( ) a second time, immediately following
* a prior invocation, shall result in NULL being returned.
*/
- current_error = NULL;
+ error_occurred = FALSE;
- return error_pointer;
+ return error_buffer;
}
#ifdef SHARED