Fixed memory leak caused by not releasing the memory from GetWindowsVersion. (#2699)

This commit is contained in:
gir489 2024-02-10 15:34:30 -05:00 committed by GitHub
parent 0275821f95
commit c87aea7f3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -116,13 +116,13 @@ namespace big
return value; return value;
} }
LPSTR GetWindowsVersion() std::unique_ptr<char[]> GetWindowsVersion()
{ {
typedef LPWSTR(WINAPI * BFS)(LPCWSTR); typedef LPWSTR(WINAPI * BFS)(LPCWSTR);
LPWSTR UTF16 = BFS(GetProcAddress(LoadLibrary("winbrand.dll"), "BrandingFormatString"))(L"%WINDOWS_LONG%"); LPWSTR UTF16 = BFS(GetProcAddress(LoadLibrary("winbrand.dll"), "BrandingFormatString"))(L"%WINDOWS_LONG%");
int BufferSize = WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, NULL, 0, NULL, NULL); int BufferSize = WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, NULL, 0, NULL, NULL);
LPSTR UTF8 = new char[BufferSize]; std::unique_ptr<char[]> UTF8(new char[BufferSize]);
WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, UTF8, BufferSize, NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, UTF8.get(), BufferSize, NULL, NULL);
// BrandingFormatString requires a GlobalFree. // BrandingFormatString requires a GlobalFree.
GlobalFree(UTF16); GlobalFree(UTF16);
return UTF8; return UTF8;