mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-20 14:25:40 +00:00
Revert "Fixed double-free during multi-threaded hidapi access"
This reverts commit 2b386b6c80.
This isn't the right approach. Even if the string itself isn't double-freed, it can be returned to the application and then freed while the application is trying to use it. This really needs to be in thread-local storage to be completely safe.
In SDL we already have a global thread-local error string, so I'm going to make an SDL-specific change to handle the error strings safely.
This commit is contained in:
@@ -255,15 +255,8 @@ static void free_hid_device(hid_device *dev)
|
||||
|
||||
static void register_winapi_error_to_buffer(wchar_t **error_buffer, const WCHAR *op)
|
||||
{
|
||||
wchar_t *old_string;
|
||||
#ifdef HIDAPI_ATOMIC_SET_POINTER
|
||||
old_string = HIDAPI_ATOMIC_SET_POINTER(error_buffer, NULL);
|
||||
#else
|
||||
old_string = *error_buffer; *error_buffer = NULL;
|
||||
#endif
|
||||
if (old_string) {
|
||||
free(old_string);
|
||||
}
|
||||
free(*error_buffer);
|
||||
*error_buffer = NULL;
|
||||
|
||||
/* Only clear out error messages if NULL is passed into op */
|
||||
if (!op) {
|
||||
@@ -327,15 +320,8 @@ static void register_winapi_error_to_buffer(wchar_t **error_buffer, const WCHAR
|
||||
|
||||
static void register_string_error_to_buffer(wchar_t **error_buffer, const WCHAR *string_error)
|
||||
{
|
||||
wchar_t *old_string;
|
||||
#ifdef HIDAPI_ATOMIC_SET_POINTER
|
||||
old_string = HIDAPI_ATOMIC_SET_POINTER(error_buffer, NULL);
|
||||
#else
|
||||
old_string = *error_buffer; *error_buffer = NULL;
|
||||
#endif
|
||||
if (old_string) {
|
||||
free(old_string);
|
||||
}
|
||||
free(*error_buffer);
|
||||
*error_buffer = NULL;
|
||||
|
||||
if (string_error) {
|
||||
*error_buffer = _wcsdup(string_error);
|
||||
|
||||
Reference in New Issue
Block a user