From 21fb2a2b683dfbe19b3be215df423a8f42bf2c64 Mon Sep 17 00:00:00 2001 From: perkj Date: Thu, 2 Apr 2015 21:55:59 -0700 Subject: [PATCH] Delete UserMediaRequestInfo before blink is notified of gUM success/failure. This changes ther order UserMediaClientImpl::OnCreateNativeTracksCompleted deletes UserMediaRequestInfo to fix a problem where the frame may have been deleted before the UserMediaRequestInfo has been deleted. BUG=472617 Review URL: https://codereview.chromium.org/1058843002 Cr-Commit-Position: refs/heads/master@{#323583} --- content/renderer/media/user_media_client_impl.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/content/renderer/media/user_media_client_impl.cc b/content/renderer/media/user_media_client_impl.cc index 1ec79a0a2ce0..e4d3fc739f49 100644 --- a/content/renderer/media/user_media_client_impl.cc +++ b/content/renderer/media/user_media_client_impl.cc @@ -653,12 +653,20 @@ void UserMediaClientImpl::OnCreateNativeTracksCompleted( DVLOG(1) << "UserMediaClientImpl::OnCreateNativeTracksComplete(" << "{request_id = " << request->request_id << "} " << "{result = " << result << "})"; - if (result == content::MEDIA_DEVICE_OK) - GetUserMediaRequestSucceeded(request->web_stream, &request->request); - else - GetUserMediaRequestFailed(&request->request, result, result_name); + // Completing the request can lead to that blink call + // cancelUserMediaRequest with the blink request and the UserMediaClientImpl + // is destroyed. Therefore, we copy (blink objects are smart pointers) the + // following objects and delete |request| before completing the blink request. + blink::WebMediaStream stream = request->web_stream; + blink::WebUserMediaRequest blink_request = request->request; + blink::WebString result_name_copy = result_name; DeleteUserMediaRequestInfo(request); + + if (result == content::MEDIA_DEVICE_OK) + GetUserMediaRequestSucceeded(stream, &blink_request); + else + GetUserMediaRequestFailed(&blink_request, result, result_name_copy); } void UserMediaClientImpl::OnDevicesEnumerated( -- 2.11.4.GIT