summaryrefslogtreecommitdiffstats
path: root/Source/cmFileLockResult.cxx
diff options
context:
space:
mode:
authorIyyappa Murugandi <iyyappam@microsoft.com>2017-05-04 22:07:45 (GMT)
committerBrad King <brad.king@kitware.com>2017-07-07 18:04:20 (GMT)
commitefaf987ad1569d5329fc60f5e1f47f3e8809bb69 (patch)
tree03cae7037d0b3a57bc036b38a2e5d6511ad9af79 /Source/cmFileLockResult.cxx
parentecadc1495b9c2e5ff5bbf265cb232f3acf1c2800 (diff)
downloadCMake-efaf987ad1569d5329fc60f5e1f47f3e8809bb69.zip
CMake-efaf987ad1569d5329fc60f5e1f47f3e8809bb69.tar.gz
CMake-efaf987ad1569d5329fc60f5e1f47f3e8809bb69.tar.bz2
cmFileLockResult: Avoid allocation for Windows error message
Diffstat (limited to 'Source/cmFileLockResult.cxx')
-rw-r--r--Source/cmFileLockResult.cxx19
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)";