From 46cea5011dac35f569ce73c67c466ec77d1af317 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 25 May 2021 19:40:14 -0500 Subject: [PATCH] Use GetModuleHandle() for kernel32.dll, since it's guaranteed to be loaded already --- src/Platform.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Platform.c b/src/Platform.c index 1cae88c..a542812 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -33,12 +33,10 @@ typedef struct tagTHREADNAME_INFO typedef HRESULT (WINAPI *SetThreadDescription_t)(HANDLE, PCWSTR); void setThreadNameWin32(const char* name) { - HMODULE hKernel32; SetThreadDescription_t setThreadDescriptionFunc; // This function is only supported on Windows 10 RS1 and later - hKernel32 = LoadLibraryA("kernel32.dll"); - setThreadDescriptionFunc = (SetThreadDescription_t)GetProcAddress(hKernel32, "SetThreadDescription"); + setThreadDescriptionFunc = (SetThreadDescription_t)GetProcAddress(GetModuleHandleA("kernel32.dll"), "SetThreadDescription"); if (setThreadDescriptionFunc != NULL) { WCHAR nameW[16]; size_t chars; @@ -46,7 +44,6 @@ void setThreadNameWin32(const char* name) { mbstowcs_s(&chars, nameW, ARRAYSIZE(nameW), name, _TRUNCATE); setThreadDescriptionFunc(GetCurrentThread(), nameW); } - FreeLibrary(hKernel32); #ifdef _MSC_VER // This method works on legacy OSes and older tools not updated to use SetThreadDescription yet,