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:
Sam Lantinga
2023-05-26 23:16:45 -07:00
parent 1c9aae9a29
commit d51f84a2e1
4 changed files with 8 additions and 45 deletions

View File

@@ -130,19 +130,8 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
* Use register_error_str(NULL) to free the error message completely. */
static void register_error_str(wchar_t **error_str, const char *msg)
{
wchar_t *old_string;
#ifdef HIDAPI_ATOMIC_SET_POINTER
old_string = HIDAPI_ATOMIC_SET_POINTER(error_str, NULL);
#else
old_string = *error_str; *error_str = NULL;
#endif
if (old_string) {
free(old_string);
}
if (msg) {
*error_str = utf8_to_wchar_t(msg);
}
free(*error_str);
*error_str = utf8_to_wchar_t(msg);
}
/* Semilar to register_error_str, but allows passing a format string with va_list args into this function. */