Fixed double-free during multi-threaded hidapi access

The error string is not protected by a mutex, and can be set from multiple threads at the same time. Without this change, it can be double-freed. It can still be double-allocated, leading to a memory leak, but at least it won't crash now.

Signed-off-by: Sam Lantinga <slouken@libsdl.org>
This commit is contained in:
Sam Lantinga 2023-05-26 20:28:20 -07:00
parent 860e52c99e
commit 2b386b6c80
4 changed files with 45 additions and 8 deletions

View file

@ -529,6 +529,7 @@ static void HIDAPI_ShutdownDiscovery(void)
/* Platform HIDAPI Implementation */
#define HIDAPI_IGNORE_DEVICE(VID, PID) SDL_HIDAPI_ShouldIgnoreDevice(VID, PID)
#define HIDAPI_ATOMIC_SET_POINTER(a, v) SDL_AtomicSetPtr((void **)a, v)
struct PLATFORM_hid_device_;
typedef struct PLATFORM_hid_device_ PLATFORM_hid_device;