[PATCH] kernel32: Return error on second attempt to free a module
Jason Edmeades
jason.edmeades at googlemail.com
Fri Jan 15 10:55:34 CST 2010
An application loads a DLL as a datafile, then uses it, then has
a loop calling FreeLibrary until the call fails. On wine this
loops forever, and this patch fixes it.
-------------- next part --------------
From e6faf3c220beca8ee2fb9f32f4d9efcd757467d9 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason.edmeades at googlemail.com>
Date: Fri, 15 Jan 2010 08:50:42 -0800
Subject: [PATCH] kernel32: Return error on second attempt to free a module
An application loads a DLL as a datafile, then uses it, then has
a loop calling FreeLibrary until the call fails. On wine this
loops forever, and this patch fixes it.
---
dlls/kernel32/module.c | 5 +++--
dlls/kernel32/tests/module.c | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c
index ff3c3a5..d480166 100644
--- a/dlls/kernel32/module.c
+++ b/dlls/kernel32/module.c
@@ -1003,8 +1003,9 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary(HINSTANCE hLibModule)
{
/* this is a LOAD_LIBRARY_AS_DATAFILE module */
char *ptr = (char *)hLibModule - 1;
- UnmapViewOfFile( ptr );
- return TRUE;
+
+ /* Return whether we successfully 'unloaded' it */
+ return UnmapViewOfFile( ptr );
}
if ((nts = LdrUnloadDll( hLibModule )) == STATUS_SUCCESS) retv = TRUE;
diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c
index 4cb30a8..35c7fc8 100644
--- a/dlls/kernel32/tests/module.c
+++ b/dlls/kernel32/tests/module.c
@@ -359,6 +359,24 @@ static void testLoadLibraryEx(void)
ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
broken(GetLastError() == ERROR_INVALID_HANDLE), /* nt4 */
"Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
+
+ /* Free the loaded dll when its the first time this dll is loaded
+ in process - First time should pass, second fail */
+ SetLastError(0xdeadbeef);
+ hmodule = LoadLibraryExA("comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
+ ok(hmodule != 0, "Expected valid module handle\n");
+
+ SetLastError(0xdeadbeef);
+ ok(FreeLibrary(hmodule),
+ "Expected to be able to free the module, failed with %d\n",
+ GetLastError());
+ SetLastError(0xdeadbeef);
+ ok(!FreeLibrary(hmodule),
+ "Unexpected ability to free the module, failed with %d\n",
+ GetLastError());
+
+ CloseHandle(hmodule);
+
}
START_TEST(module)
--
1.6.0.4
More information about the wine-patches
mailing list