From: Tom Sutcliffe Date: Sat, 9 Mar 2019 13:41:22 +0000 (+0000) Subject: Fix Win32 p11_dl_error crash X-Git-Tag: 0.23.16~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbe95e35f8309493094c93d882d0c18e8063f292;p=p11-kit 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. --- 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