Bug 186152

Summary: Fix leak of AudioDeviceID array due to an early return in AudioDeviceMac::GetNumberDevices()
Product: WebKit Reporter: David Kilzer (:ddkilzer) <ddkilzer>
Component: WebRTCAssignee: David Kilzer (:ddkilzer) <ddkilzer>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, bfulgham, commit-queue, eric.carlson, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.chromium.org/p/webrtc/issues/detail?id=9348
Attachments:
Description Flags
Patch v1
none
Patch v2
none
Patch v3 none

Description David Kilzer (:ddkilzer) 2018-05-31 11:19:16 PDT
Fix leak of AudioDeviceID array due to an early return in AudioDeviceMac::GetNumberDevices():

Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc:1586:3: warning: Potential leak of memory pointed to by 'deviceIds'
  WEBRTC_CA_RETURN_ON_ERR(AudioObjectGetPropertyData(kAudioObjectSystemObject,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_device/mac/audio_device_mac.cc:30:7: note: expanded from macro 'WEBRTC_CA_RETURN_ON_ERR'
      logCAMsg(rtc::LS_ERROR, "Error in " #expr, (const char*)&err); \
      ^~~~~~~~

We can use RAII with std::unique_ptr<>() to fix the leak and remove manual release of the memory using this technique:
<https://www.codeproject.com/Articles/820931/Using-std-unique-ptr-RAII-with-malloc-and-free>
Comment 1 Radar WebKit Bug Importer 2018-05-31 11:26:07 PDT
<rdar://problem/40692824>
Comment 2 David Kilzer (:ddkilzer) 2018-05-31 11:34:05 PDT
Created attachment 341679 [details]
Patch v1
Comment 3 Alex Christensen 2018-05-31 11:39:28 PDT
Comment on attachment 341679 [details]
Patch v1

Can't we use std::make_unique?
Comment 4 David Kilzer (:ddkilzer) 2018-05-31 12:03:31 PDT
(In reply to Alex Christensen from comment #3)
> Comment on attachment 341679 [details]
> Patch v1
> 
> Can't we use std::make_unique?

I was aiming to change the code as little as possible, but yes we can!  New patch forthcoming.
Comment 5 David Kilzer (:ddkilzer) 2018-05-31 12:04:03 PDT
Created attachment 341681 [details]
Patch v2
Comment 6 David Kilzer (:ddkilzer) 2018-05-31 12:11:24 PDT
Created attachment 341684 [details]
Patch v3

Remove 'const' from 'numberDevices' since it used in an in-out context in AudioObjectGetPropertyData().
Comment 7 WebKit Commit Bot 2018-05-31 12:51:35 PDT
Comment on attachment 341684 [details]
Patch v3

Clearing flags on attachment: 341684

Committed r232365: <https://trac.webkit.org/changeset/232365>
Comment 8 WebKit Commit Bot 2018-05-31 12:51:37 PDT
All reviewed patches have been landed.  Closing bug.