summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sutcliffe <tomsci@me.com>2019-03-09 13:41:22 +0000
committerDaiki Ueno <ueno@gnu.org>2019-03-10 11:02:12 +0100
commitcbe95e35f8309493094c93d882d0c18e8063f292 (patch)
treee4ab0d269f880f9bcf8083903d4b1cff96760e2c
parent4a925177a81c2566d2a81a0a450607a5ff4d9048 (diff)
Fix Win32 p11_dl_error crash
Caused by returning a buffer that wasn't allocated with malloc and needed to be freed with LocalFree() instead. The fix is to strdup msg_buf so what's returned can be free()d.
-rw-r--r--common/compat.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/common/compat.c b/common/compat.c
index 48614fa..5f47534 100644
--- a/common/compat.c
+++ b/common/compat.c
@@ -270,6 +270,7 @@ p11_dl_error (void)
{
DWORD code = GetLastError();
LPVOID msg_buf;
+ char *result;
FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
@@ -278,7 +279,9 @@ p11_dl_error (void)
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&msg_buf, 0, NULL);
- return msg_buf;
+ result = strdup (msg_buf);
+ LocalFree (msg_buf);
+ return result;
}
int