mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-28 03:11:51 +00:00
Make sure hidapi error handling is thread-safe
The hidapi method of storing the error on the device is not thread-safe, and not only could it result in a double free if multiple threads were setting the error at the same time, but SDL could be trying to use the error message and have it be freed out from under it by another thread. Use SDL's error functions since they already use thread-local storage.
This commit is contained in:
@@ -131,7 +131,12 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
|
||||
static void register_error_str(wchar_t **error_str, const char *msg)
|
||||
{
|
||||
free(*error_str);
|
||||
#ifdef HIDAPI_USING_SDL_RUNTIME
|
||||
/* Thread-safe error handling */
|
||||
SDL_SetError("%s", msg);
|
||||
#else
|
||||
*error_str = utf8_to_wchar_t(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Semilar to register_error_str, but allows passing a format string with va_list args into this function. */
|
||||
|
||||
Reference in New Issue
Block a user