ntdll: Fix the file mapping view leak in the case of module loading failure. Take 2.

Dmitry Timoshkov dmitry at baikal.ru
Mon Feb 27 10:11:33 CST 2012


---
 dlls/ntdll/loader.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 381e2ac..5600a0c 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -119,6 +119,7 @@ static FARPROC find_ordinal_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY
                                     DWORD exp_size, DWORD ordinal, LPCWSTR load_path );
 static FARPROC find_named_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
                                   DWORD exp_size, const char *name, int hint, LPCWSTR load_path );
+static void free_modref( WINE_MODREF *wm );
 
 /* convert PE image VirtualAddress to Real Address */
 static inline void *get_rva( HMODULE module, DWORD va )
@@ -1479,7 +1480,7 @@ static NTSTATUS load_native_dll( LPCWSTR load_path, LPCWSTR name, HANDLE file,
     LARGE_INTEGER size;
     IMAGE_NT_HEADERS *nt;
     SIZE_T len = 0;
-    WINE_MODREF *wm;
+    WINE_MODREF *wm = NULL;
     NTSTATUS status;
 
     TRACE("Trying native dll %s\n", debugstr_w(name));
@@ -1548,6 +1549,11 @@ static NTSTATUS load_native_dll( LPCWSTR load_path, LPCWSTR name, HANDLE file,
     *pwm = wm;
     status = STATUS_SUCCESS;
 done:
+    if (status)
+    {
+        if (wm) free_modref( wm );
+        else if (module) NtUnmapViewOfSection( NtCurrentProcess(), module );
+    }
     NtClose( mapping );
     return status;
 }
-- 
1.7.8.4




More information about the wine-patches mailing list