Bug 186152 - Fix leak of AudioDeviceID array due to an early return in AudioDeviceMac::GetNumberDevices()
Summary: Fix leak of AudioDeviceID array due to an early return in AudioDeviceMac::Get...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-05-31 11:19 PDT by David Kilzer (:ddkilzer)
Modified: 2018-05-31 12:51 PDT (History)
6 users (show)

See Also:


Attachments
Patch v1 (5.57 KB, patch)
2018-05-31 11:34 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v2 (5.65 KB, patch)
2018-05-31 12:04 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v3 (5.53 KB, patch)
2018-05-31 12:11 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.