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.
{
DWORD code = GetLastError();
LPVOID msg_buf;
+ char *result;
FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&msg_buf, 0, NULL);
- return msg_buf;
+ result = strdup (msg_buf);
+ LocalFree (msg_buf);
+ return result;
}
int