From 51996593b805cc79ba3a67ea4c721baa60e1c70e Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 22 Mar 2013 09:00:40 -0500 Subject: [PATCH 1/1] Move FreeLibrary call to win32_global_cleanup() --- src/wim.c | 3 +++ src/win32.c | 37 ++++++++++++++++++++++++------------- src/win32.h | 3 +++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/wim.c b/src/wim.c index ac869302..823d3a44 100644 --- a/src/wim.c +++ b/src/wim.c @@ -704,4 +704,7 @@ wimlib_global_cleanup() { libxml_global_cleanup(); iconv_global_cleanup(); +#ifdef __WIN32__ + win32_global_cleanup(); +#endif } diff --git a/src/win32.c b/src/win32.c index 75867e89..ce94b049 100644 --- a/src/win32.c +++ b/src/win32.c @@ -60,6 +60,8 @@ static HANDLE (WINAPI *win32func_FindFirstStreamW)(LPCWSTR lpFileName, static BOOL (WINAPI *win32func_FindNextStreamW)(HANDLE hFindStream, LPVOID lpFindStreamData) = NULL; +static HMODULE hKernel32 = NULL; + /* Try to dynamically load some functions */ void win32_global_init() @@ -67,34 +69,43 @@ win32_global_init() DWORD err; bool warned; - DEBUG("Loading Kernel32.dll"); - HMODULE lib = LoadLibraryA("Kernel32.dll"); - if (lib == NULL) { - err = GetLastError(); - WARNING("Can't load Kernel32.dll"); - win32_error(err); - return; + if (hKernel32 == NULL) { + DEBUG("Loading Kernel32.dll"); + hKernel32 = LoadLibraryA("Kernel32.dll"); + if (hKernel32 == NULL) { + err = GetLastError(); + WARNING("Can't load Kernel32.dll"); + win32_error(err); + return; + } } DEBUG("Looking for FindFirstStreamW"); - win32func_FindFirstStreamW = (void*)GetProcAddress(lib, "FindFirstStreamW"); + win32func_FindFirstStreamW = (void*)GetProcAddress(hKernel32, "FindFirstStreamW"); if (!win32func_FindFirstStreamW) { WARNING("Could not find function FindFirstStreamW() in Kernel32.dll!"); WARNING("Capturing alternate data streams will not be supported."); - goto out_free_lib; + return; } DEBUG("Looking for FindNextStreamW"); - win32func_FindNextStreamW = (void*)GetProcAddress(lib, "FindNextStreamW"); + win32func_FindNextStreamW = (void*)GetProcAddress(hKernel32, "FindNextStreamW"); if (!win32func_FindNextStreamW) { WARNING("Could not find function FindNextStreamW() in Kernel32.dll!"); WARNING("Capturing alternate data streams will not be supported."); win32func_FindFirstStreamW = NULL; } -out_free_lib: - DEBUG("Closing Kernel32.dll"); - FreeLibrary(lib); +} + +void +win32_global_cleanup() +{ + if (hKernel32 != NULL) { + DEBUG("Closing Kernel32.dll"); + FreeLibrary(hKernel32); + hKernel32 = NULL; + } } static const char *access_denied_msg = diff --git a/src/win32.h b/src/win32.h index 8b5a9dfb..bef8da65 100644 --- a/src/win32.h +++ b/src/win32.h @@ -80,4 +80,7 @@ rename_replacement(const char *oldpath, const char *newpath); extern void win32_global_init(); +extern void +win32_global_cleanup(); + #endif /* _WIMLIB_WIN32_H */ -- 2.43.0