diff --git a/include/SDL3/SDL_camera.h b/include/SDL3/SDL_camera.h index d351ea2dac..25d7a32d0f 100644 --- a/include/SDL3/SDL_camera.h +++ b/include/SDL3/SDL_camera.h @@ -230,8 +230,7 @@ extern SDL_DECLSPEC SDL_CameraSpec *SDLCALL SDL_GetCameraDeviceSupportedFormats( /** * Get the human-readable device name for a camera. * - * The returned string is owned by the caller; please release it with - * SDL_free() when done with it. + * The returned string follows the SDL_GetStringRule. * * \param instance_id the camera device instance ID * \returns a human-readable device name, or NULL on error; call @@ -243,7 +242,7 @@ extern SDL_DECLSPEC SDL_CameraSpec *SDLCALL SDL_GetCameraDeviceSupportedFormats( * * \sa SDL_GetCameraDevices */ -extern SDL_DECLSPEC char * SDLCALL SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id); +extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id); /** * Get the position of the camera in relation to the system. diff --git a/src/camera/SDL_camera.c b/src/camera/SDL_camera.c index 8009136497..28323abccf 100644 --- a/src/camera/SDL_camera.c +++ b/src/camera/SDL_camera.c @@ -285,7 +285,7 @@ static void DestroyPhysicalCameraDevice(SDL_CameraDevice *device) camera_driver.impl.FreeDeviceHandle(device); SDL_DestroyMutex(device->lock); SDL_free(device->all_specs); - SDL_free(device->name); + SDL_FreeLater(device->name); // this is returned in SDL_GetCameraDeviceName. SDL_free(device); } } @@ -662,12 +662,12 @@ int SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec) return 0; } -char *SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id) +const char *SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id) { char *retval = NULL; SDL_CameraDevice *device = ObtainPhysicalCameraDevice(instance_id); if (device) { - retval = SDL_strdup(device->name); + retval = device->name; ReleaseCameraDevice(device); } return retval; diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index e283c17591..9294d16cd5 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -227,7 +227,7 @@ SDL_DYNAPI_PROC(char*,SDL_GetBasePath,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetBooleanProperty,(SDL_PropertiesID a, const char *b, SDL_bool c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetCPUCacheLineSize,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetCPUCount,(void),(),return) -SDL_DYNAPI_PROC(char*,SDL_GetCameraDeviceName,(SDL_CameraDeviceID a),(a),return) +SDL_DYNAPI_PROC(const char*,SDL_GetCameraDeviceName,(SDL_CameraDeviceID a),(a),return) SDL_DYNAPI_PROC(SDL_CameraPosition,SDL_GetCameraDevicePosition,(SDL_CameraDeviceID a),(a),return) SDL_DYNAPI_PROC(SDL_CameraSpec*,SDL_GetCameraDeviceSupportedFormats,(SDL_CameraDeviceID a, int *b),(a,b),return) SDL_DYNAPI_PROC(SDL_CameraDeviceID*,SDL_GetCameraDevices,(int *a),(a),return) diff --git a/test/testcamera.c b/test/testcamera.c index 5502007fcb..0a8d4a4a01 100644 --- a/test/testcamera.c +++ b/test/testcamera.c @@ -98,7 +98,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) SDL_Log("Saw %d camera devices.", devcount); for (i = 0; i < devcount; i++) { const SDL_CameraDeviceID device = devices[i]; - char *name = SDL_GetCameraDeviceName(device); + const char *name = SDL_GetCameraDeviceName(device); const SDL_CameraPosition position = SDL_GetCameraDevicePosition(device); const char *posstr = ""; if (position == SDL_CAMERA_POSITION_FRONT_FACING) { @@ -112,7 +112,6 @@ int SDL_AppInit(void **appstate, int argc, char *argv[]) camera_id = device; } SDL_Log(" - Camera #%d: %s %s", i, posstr, name); - SDL_free(name); } if (!camera_id) {