Diff
Modified: trunk/Source/ThirdParty/libwebrtc/ChangeLog (232364 => 232365)
--- trunk/Source/ThirdParty/libwebrtc/ChangeLog 2018-05-31 19:46:56 UTC (rev 232364)
+++ trunk/Source/ThirdParty/libwebrtc/ChangeLog 2018-05-31 19:51:30 UTC (rev 232365)
@@ -1,3 +1,16 @@
+2018-05-31 David Kilzer <[email protected]>
+
+ Fix leak of AudioDeviceID array due to an early return in AudioDeviceMac::GetNumberDevices()
+ <https://webkit.org/b/186152>
+ <rdar://problem/40692824>
+
+ Reviewed by Alex Christensen.
+
+ * Source/webrtc/modules/audio_device/mac/audio_device_mac.cc:
+ Use std::make_unique<> so that memory is allocated and
+ deallocated automatically. Remove manual calls to free().
+ * WebKit/0011-Fix-AudioDeviceID-array-leak.patch: Add.
+
2018-05-30 David Kilzer <[email protected]>
Fix leak of a CVPixelBufferRef due to early rerturn in -[RTCVideoEncoderH264 encode:codecSpecificInfo:frameTypes:]
Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc (232364 => 232365)
--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc 2018-05-31 19:46:56 UTC (rev 232364)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc 2018-05-31 19:51:30 UTC (rev 232365)
@@ -19,6 +19,7 @@
#include <ApplicationServices/ApplicationServices.h>
#include <libkern/OSAtomic.h> // OSAtomicCompareAndSwap()
#include <mach/mach.h> // mach_task_self()
+#include <memory> // std::make_unique<>() and std::unique_ptr<>()
#include <sys/sysctl.h> // sysctlbyname()
namespace webrtc {
@@ -1564,8 +1565,8 @@
return 0;
}
- AudioDeviceID* deviceIds = (AudioDeviceID*)malloc(size);
UInt32 numberDevices = size / sizeof(AudioDeviceID);
+ auto deviceIds = std::make_unique<AudioDeviceID[]>(numberDevices);
AudioBufferList* bufferList = NULL;
UInt32 numberScopedDevices = 0;
@@ -1597,7 +1598,7 @@
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 @@
}
if (!listOK) {
- if (deviceIds) {
- free(deviceIds);
- deviceIds = NULL;
- }
-
if (bufferList) {
free(bufferList);
bufferList = NULL;
@@ -1654,12 +1650,6 @@
return -1;
}
- // Happy ending
- if (deviceIds) {
- free(deviceIds);
- deviceIds = NULL;
- }
-
return numberScopedDevices;
}
Added: trunk/Source/ThirdParty/libwebrtc/WebKit/0011-Fix-AudioDeviceID-array-leak.patch (0 => 232365)
--- trunk/Source/ThirdParty/libwebrtc/WebKit/0011-Fix-AudioDeviceID-array-leak.patch (rev 0)
+++ trunk/Source/ThirdParty/libwebrtc/WebKit/0011-Fix-AudioDeviceID-array-leak.patch 2018-05-31 19:51:30 UTC (rev 232365)
@@ -0,0 +1,56 @@
+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 <ApplicationServices/ApplicationServices.h>
+ #include <libkern/OSAtomic.h> // OSAtomicCompareAndSwap()
+ #include <mach/mach.h> // mach_task_self()
++#include <memory> // std::make_unique<>() and std::unique_ptr<>()
+ #include <sys/sysctl.h> // 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<AudioDeviceID[]>(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;
+ }
+