From c87aea7f3cd581915ba0a1b3cddb9ab4fc9ef0a4 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:34:30 -0500 Subject: [PATCH] Fixed memory leak caused by not releasing the memory from GetWindowsVersion. (#2699) --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 510fda16..3b5b68fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,13 +116,13 @@ namespace big return value; } - LPSTR GetWindowsVersion() + std::unique_ptr GetWindowsVersion() { typedef LPWSTR(WINAPI * BFS)(LPCWSTR); LPWSTR UTF16 = BFS(GetProcAddress(LoadLibrary("winbrand.dll"), "BrandingFormatString"))(L"%WINDOWS_LONG%"); int BufferSize = WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, NULL, 0, NULL, NULL); - LPSTR UTF8 = new char[BufferSize]; - WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, UTF8, BufferSize, NULL, NULL); + std::unique_ptr UTF8(new char[BufferSize]); + WideCharToMultiByte(CP_UTF8, 0, UTF16, -1, UTF8.get(), BufferSize, NULL, NULL); // BrandingFormatString requires a GlobalFree. GlobalFree(UTF16); return UTF8;