Correctly process malloc() error in local_add() malloc() may fail, so propagate this error to caller of dlopen().
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
diff --git a/dlfcn.c b/dlfcn.c
index 26135e3..7fe4701 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -72,34 +72,36 @@ static local_object *local_search( HMODULE hModule )
return NULL;
}
-static void local_add( HMODULE hModule )
+static BOOL local_add( HMODULE hModule )
{
local_object *pobject;
local_object *nobject;
if( hModule == NULL )
- return;
+ return TRUE;
pobject = local_search( hModule );
/* Do not add object again if it's already on the list */
if( pobject )
- return;
+ return TRUE;
for( pobject = &first_object; pobject->next; pobject = pobject->next );
nobject = (local_object*) malloc( sizeof( local_object ) );
- /* Should this be enough to fail local_add, and therefore also fail
- * dlopen?
- */
if( !nobject )
- return;
+ {
+ SetLastError( ERROR_NOT_ENOUGH_MEMORY );
+ return FALSE;
+ }
pobject->next = nobject;
nobject->next = NULL;
nobject->previous = pobject;
nobject->hModule = hModule;
+
+ return TRUE;
}
static void local_rem( HMODULE hModule )
@@ -287,7 +289,12 @@ void *dlopen( const char *file, int mode )
*/
if( (mode & RTLD_LOCAL) && dwProcModsBefore != dwProcModsAfter )
{
- local_add( hModule );
+ if( !local_add( hModule ) )
+ {
+ save_err_str( lpFileName );
+ FreeLibrary( hModule );
+ hModule = NULL;
+ }
}
else if( !(mode & RTLD_LOCAL) && dwProcModsBefore == dwProcModsAfter )
{