diff options
author | Brad King <brad.king@kitware.com> | 2017-07-11 11:38:50 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-07-11 11:38:54 (GMT) |
commit | de72d5dda6909093eb3fb6f8c0d53633e5bd9fdf (patch) | |
tree | 42d517510db9844434446385dd7a7f930f6c2119 /Source | |
parent | 970569a941a3259f5303a5090ed7bca7bb6e6d7e (diff) | |
parent | efaf987ad1569d5329fc60f5e1f47f3e8809bb69 (diff) | |
download | CMake-de72d5dda6909093eb3fb6f8c0d53633e5bd9fdf.zip CMake-de72d5dda6909093eb3fb6f8c0d53633e5bd9fdf.tar.gz CMake-de72d5dda6909093eb3fb6f8c0d53633e5bd9fdf.tar.bz2 |
Merge topic 'file-LOCK-windows-message'
efaf987a cmFileLockResult: Avoid allocation for Windows error message
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1035
Diffstat (limited to 'Source')
-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)"; |