Make sure we always copy the data returned using SDL_GetStringRule

This prevents race conditions where calling an API from one thread returns the data and it's freed by updates on another thread
This commit is contained in:
Sam Lantinga
2024-07-18 15:56:41 -07:00
parent ef884c8aa6
commit bb96320cc4
19 changed files with 66 additions and 71 deletions

View File

@@ -286,7 +286,7 @@ static void DestroyPhysicalCamera(SDL_Camera *device)
camera_driver.impl.FreeDeviceHandle(device);
SDL_DestroyMutex(device->lock);
SDL_free(device->all_specs);
SDL_FreeLater(device->name); // this is returned in SDL_GetCameraName.
SDL_free(device->name);
SDL_free(device);
}
}
@@ -674,10 +674,10 @@ int SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec)
const char *SDL_GetCameraName(SDL_CameraID instance_id)
{
char *retval = NULL;
const char *retval = NULL;
SDL_Camera *device = ObtainPhysicalCamera(instance_id);
if (device) {
retval = device->name;
retval = SDL_CreateTemporaryString(device->name);
ReleaseCamera(device);
}
return retval;