use GetModuleHandleW() to retrieve kernel32.dll handle (bug #5390.)

SDL_systhread.c and SDL_syslocale.c used to call LoadLibrary() without
calling FreeLibrary() later.  GetModuleHandleW() should always succeed
because GetModuleHandleW() itself is imported from kernel32.dll and we
don't need to bother releasing it.
This commit is contained in:
Ozkan Sezer 2020-12-22 17:10:02 +03:00
parent 9f655fe522
commit a19c008a7f
2 changed files with 6 additions and 6 deletions

View File

@ -23,7 +23,7 @@
#include "../../core/windows/SDL_windows.h" #include "../../core/windows/SDL_windows.h"
#include "../SDL_syslocale.h" #include "../SDL_syslocale.h"
typedef BOOL (WINAPI *pfnGetUserPreferredUILanguages)(DWORD,PULONG,/*PZZWSTR*/WCHAR*,PULONG); typedef BOOL (WINAPI *pfnGetUserPreferredUILanguages)(DWORD,PULONG,WCHAR*,PULONG);
#ifndef MUI_LANGUAGE_NAME #ifndef MUI_LANGUAGE_NAME
#define MUI_LANGUAGE_NAME 0x8 #define MUI_LANGUAGE_NAME 0x8
#endif #endif
@ -100,7 +100,7 @@ void
SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
{ {
if (!kernel32) { if (!kernel32) {
kernel32 = LoadLibraryW(L"kernel32.dll"); kernel32 = GetModuleHandleW(L"kernel32.dll");
if (kernel32) { if (kernel32) {
pGetUserPreferredUILanguages = (pfnGetUserPreferredUILanguages) GetProcAddress(kernel32, "GetUserPreferredUILanguages"); pGetUserPreferredUILanguages = (pfnGetUserPreferredUILanguages) GetProcAddress(kernel32, "GetUserPreferredUILanguages");
} }

View File

@ -163,7 +163,7 @@ SDL_SYS_SetupThread(const char *name)
static HMODULE kernel32 = 0; static HMODULE kernel32 = 0;
if (!kernel32) { if (!kernel32) {
kernel32 = LoadLibraryW(L"kernel32.dll"); kernel32 = GetModuleHandleW(L"kernel32.dll");
if (kernel32) { if (kernel32) {
pSetThreadDescription = (pfnSetThreadDescription) GetProcAddress(kernel32, "SetThreadDescription"); pSetThreadDescription = (pfnSetThreadDescription) GetProcAddress(kernel32, "SetThreadDescription");
} }