diff --git a/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc b/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc index c585c32cafc..89ea9317c1f 100644 --- a/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc +++ b/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc @@ -19,6 +19,7 @@ #include #include // OSAtomicCompareAndSwap() #include // mach_task_self() +#include // std::make_unique<>() and std::unique_ptr<>() #include // sysctlbyname() namespace webrtc { @@ -1564,8 +1565,8 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, return 0; } - AudioDeviceID* deviceIds = (AudioDeviceID*)malloc(size); UInt32 numberDevices = size / sizeof(AudioDeviceID); + auto deviceIds = std::make_unique(numberDevices); AudioBufferList* bufferList = NULL; UInt32 numberScopedDevices = 0; @@ -1597,7 +1598,7 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, bool listOK = true; WEBRTC_CA_LOG_ERR(AudioObjectGetPropertyData( - kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, deviceIds)); + kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, deviceIds.get())); if (err != noErr) { listOK = false; } else { @@ -1641,11 +1642,6 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, } if (!listOK) { - if (deviceIds) { - free(deviceIds); - deviceIds = NULL; - } - if (bufferList) { free(bufferList); bufferList = NULL; @@ -1654,12 +1650,6 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, return -1; } - // Happy ending - if (deviceIds) { - free(deviceIds); - deviceIds = NULL; - } - return numberScopedDevices; }