Skip to content

Commit e12f497

Browse files
committed
Avoid double free in MediaCaptureDevicesDispatcher
Fix e7d3a58
1 parent e7d3a58 commit e12f497

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

src/media/media_capture_devices_dispatcher.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,3 @@ MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() {
165165
return &(*video_devices.begin());
166166
}
167167

168-
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
169-
return Singleton<MediaCaptureDevicesDispatcher>::get();
170-
}

src/media/media_capture_devices_dispatcher.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class MediaCaptureDevicesDispatcher
3333
virtual ~Observer() {}
3434
};
3535

36-
static MediaCaptureDevicesDispatcher* GetInstance();
37-
3836
MediaCaptureDevicesDispatcher();
3937
virtual ~MediaCaptureDevicesDispatcher();
4038

@@ -67,7 +65,6 @@ class MediaCaptureDevicesDispatcher
6765
const content::MediaStreamDevice* GetFirstAvailableAudioDevice();
6866
const content::MediaStreamDevice* GetFirstAvailableVideoDevice();
6967

70-
7168
private:
7269
friend class base::RefCountedThreadSafe<MediaCaptureDevicesDispatcher>;
7370

src/media/media_internals.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,5 @@ MediaInternals::GetMediaCaptureDevicesDispatcher() {
125125
}
126126

127127
MediaInternals::MediaInternals()
128-
: media_devices_dispatcher_(MediaCaptureDevicesDispatcher::GetInstance()) {
128+
: media_devices_dispatcher_(new MediaCaptureDevicesDispatcher()) {
129129
}

src/media/media_stream_devices_controller.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,26 @@ const std::string& MediaStreamDevicesController::GetSecurityOriginSpec() const {
115115
void MediaStreamDevicesController::Accept(bool update_content_setting) {
116116
// Get the default devices for the request.
117117
content::MediaStreamDevices devices;
118+
MediaCaptureDevicesDispatcher* dispatcher =
119+
MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher();
118120
switch (request_.request_type) {
119121
case content::MEDIA_OPEN_DEVICE: {
120122
const content::MediaStreamDevice* device = NULL;
121123
// For open device request pick the desired device or fall back to the
122124
// first available of the given type.
123125
if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
124-
device = MediaCaptureDevicesDispatcher::GetInstance()->
126+
device = dispatcher->
125127
GetRequestedAudioDevice(request_.requested_audio_device_id);
126128
// TODO(wjia): Confirm this is the intended behavior.
127129
if (!device) {
128-
device = MediaCaptureDevicesDispatcher::GetInstance()->
129-
GetFirstAvailableAudioDevice();
130+
device = dispatcher->GetFirstAvailableAudioDevice();
130131
}
131132
} else if (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
132133
// Pepper API opens only one device at a time.
133-
device = MediaCaptureDevicesDispatcher::GetInstance()->
134-
GetRequestedVideoDevice(request_.requested_video_device_id);
134+
device = dispatcher->GetRequestedVideoDevice(request_.requested_video_device_id);
135135
// TODO(wjia): Confirm this is the intended behavior.
136136
if (!device) {
137-
device = MediaCaptureDevicesDispatcher::GetInstance()->
138-
GetFirstAvailableVideoDevice();
137+
device = dispatcher->GetFirstAvailableVideoDevice();
139138
}
140139
}
141140
if (device)
@@ -148,17 +147,15 @@ void MediaStreamDevicesController::Accept(bool update_content_setting) {
148147
// Get the exact audio or video device if an id is specified.
149148
if (!request_.requested_audio_device_id.empty()) {
150149
const content::MediaStreamDevice* audio_device =
151-
MediaCaptureDevicesDispatcher::GetInstance()->
152-
GetRequestedAudioDevice(request_.requested_audio_device_id);
150+
dispatcher->GetRequestedAudioDevice(request_.requested_audio_device_id);
153151
if (audio_device) {
154152
devices.push_back(*audio_device);
155153
needs_audio_device = false;
156154
}
157155
}
158156
if (!request_.requested_video_device_id.empty()) {
159157
const content::MediaStreamDevice* video_device =
160-
MediaCaptureDevicesDispatcher::GetInstance()->
161-
GetRequestedVideoDevice(request_.requested_video_device_id);
158+
dispatcher->GetRequestedVideoDevice(request_.requested_video_device_id);
162159
if (video_device) {
163160
devices.push_back(*video_device);
164161
needs_video_device = false;

0 commit comments

Comments
 (0)