diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index 65c24ff9..9c35ad7d 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -687,10 +687,12 @@ static _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, template static DWORD FormatMessageA(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments) { - std::unique_ptr > lpBuffer; - DWORD dwResult = FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast((LPSTR*)get_ptr(lpBuffer)), 0, Arguments); - if (dwResult) - str.assign(lpBuffer.get(), dwResult); + LPSTR lpBuffer; + DWORD dwResult = FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast(&lpBuffer), 0, Arguments); + if (dwResult) { + str.assign(lpBuffer, dwResult); + LocalFree(lpBuffer); + } return dwResult; } @@ -702,10 +704,12 @@ static DWORD FormatMessageA(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ template static DWORD FormatMessageW(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments) { - std::unique_ptr > lpBuffer; - DWORD dwResult = FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast((LPWSTR*)get_ptr(lpBuffer)), 0, Arguments); - if (dwResult) - str.assign(lpBuffer.get(), dwResult); + LPWSTR lpBuffer; + DWORD dwResult = FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast(&lpBuffer), 0, Arguments); + if (dwResult) { + str.assign(lpBuffer, dwResult); + LocalFree(lpBuffer); + } return dwResult; }