diff --git a/modules/audio_device/mac/audio_device_mac.cc b/modules/audio_device/mac/audio_device_mac.cc index c585c32caf..ed490c6d95 100644 --- a/modules/audio_device/mac/audio_device_mac.cc +++ b/modules/audio_device/mac/audio_device_mac.cc @@ -14,6 +14,7 @@ #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" #include "rtc_base/platform_thread.h" +#include "rtc_base/ptr_util.h" #include "system_wrappers/include/event_wrapper.h" #include @@ -1564,8 +1565,8 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, return 0; } - AudioDeviceID* deviceIds = (AudioDeviceID*)malloc(size); UInt32 numberDevices = size / sizeof(AudioDeviceID); + const auto deviceIds = rtc::MakeUnique(numberDevices); AudioBufferList* bufferList = NULL; UInt32 numberScopedDevices = 0; @@ -1596,8 +1597,9 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, // Then list the rest of the devices bool listOK = true; - WEBRTC_CA_LOG_ERR(AudioObjectGetPropertyData( - kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, deviceIds)); + WEBRTC_CA_LOG_ERR(AudioObjectGetPropertyData(kAudioObjectSystemObject, + &propertyAddress, 0, NULL, &size, + deviceIds.get())); if (err != noErr) { listOK = false; } else { @@ -1641,25 +1643,13 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, } if (!listOK) { - if (deviceIds) { - free(deviceIds); - deviceIds = NULL; - } - if (bufferList) { free(bufferList); bufferList = NULL; } - return -1; } - // Happy ending - if (deviceIds) { - free(deviceIds); - deviceIds = NULL; - } - return numberScopedDevices; }