avoid using LocalFree on FormatMessageA buffer (#3772)

* avoid using localfree for FormatMessageA buffer because it is only supported on windows 10

Co-authored-by: Ori Levari <orlevari@microsoft.com>
This commit is contained in:
Ori Levari 2020-04-30 20:51:09 -07:00 committed by GitHub
parent f68a326bd9
commit ad63e2593d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -178,11 +178,10 @@ inline OrtFileType DTToFileType(DWORD dwFileAttributes) {
return OrtFileType::TYPE_REG;
}
inline std::string FormatErrorCode(DWORD dw) {
char* lpMsgBuf;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpMsgBuf, 0, NULL);
std::string s(lpMsgBuf);
LocalFree(lpMsgBuf);
static const DWORD bufferLength = 64 * 1024;
std::string s(bufferLength, '\0');
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)s.data(), bufferLength / sizeof(TCHAR), NULL);
return s;
}
template <typename T>