diff options
Diffstat (limited to 'Source/cmFileLockResult.cxx')
-rw-r--r-- | Source/cmFileLockResult.cxx | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/Source/cmFileLockResult.cxx b/Source/cmFileLockResult.cxx index a040705..9ca5d8a 100644 --- a/Source/cmFileLockResult.cxx +++ b/Source/cmFileLockResult.cxx @@ -5,6 +5,7 @@ #include <errno.h> #include <string.h> +#define WINMSG_BUF_LEN (1024) cmFileLockResult cmFileLockResult::MakeOk() { return cmFileLockResult(OK, 0); @@ -53,18 +54,12 @@ std::string cmFileLockResult::GetOutputMessage() const case SYSTEM: #if defined(_WIN32) { - char* errorText = NULL; - - // http://stackoverflow.com/a/455533/2288008 - DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS; - ::FormatMessageA(flags, NULL, this->ErrorValue, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&errorText, 0, NULL); - - if (errorText != NULL) { - const std::string message = errorText; - ::LocalFree(errorText); + char winmsg[WINMSG_BUF_LEN]; + DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; + if (FormatMessageA(flags, NULL, this->ErrorValue, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)winmsg, WINMSG_BUF_LEN, NULL)) { + const std::string message = winmsg; return message; } else { return "Internal error (FormatMessageA failed)"; |