From dc7515e3d7456201d5d841a6561dd565d23eaebd Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Mon, 16 Apr 2018 10:51:48 +0200 Subject: Bug 1426129 - Hold CamerasChild via promoting "this" to a RefPtr. r=pehrsons, a=RyanVM --- dom/media/systemservices/CamerasChild.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'dom/media/systemservices/CamerasChild.cpp') diff --git a/dom/media/systemservices/CamerasChild.cpp b/dom/media/systemservices/CamerasChild.cpp index 0f7d1c1df..a3fbec850 100644 --- a/dom/media/systemservices/CamerasChild.cpp +++ b/dom/media/systemservices/CamerasChild.cpp @@ -35,7 +35,9 @@ CamerasSingleton::CamerasSingleton() : mCamerasMutex("CamerasSingleton::mCamerasMutex"), mCameras(nullptr), mCamerasChildThread(nullptr), - mFakeDeviceChangeEventThread(nullptr) { + mFakeDeviceChangeEventThread(nullptr), + mInShutdown(false) +{ LOG(("CamerasSingleton: %p", this)); } @@ -285,6 +287,7 @@ CamerasChild::NumberOfCapabilities(CaptureEngine aCapEngine, LOG((__PRETTY_FUNCTION__)); LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8)); nsCString unique_id(deviceUniqueIdUTF8); + RefPtr deathGrip = this; nsCOMPtr runnable = mozilla::NewNonOwningRunnableMethod (this, &CamerasChild::SendNumberOfCapabilities, aCapEngine, unique_id); @@ -321,6 +324,7 @@ int CamerasChild::EnsureInitialized(CaptureEngine aCapEngine) { LOG((__PRETTY_FUNCTION__)); + RefPtr deathGrip = this; nsCOMPtr runnable = mozilla::NewNonOwningRunnableMethod (this, &CamerasChild::SendEnsureInitialized, aCapEngine); @@ -336,6 +340,7 @@ CamerasChild::GetCaptureCapability(CaptureEngine aCapEngine, webrtc::CaptureCapability& capability) { LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number)); + RefPtr deathGrip = this; nsCString unique_id(unique_idUTF8); nsCOMPtr runnable = mozilla::NewNonOwningRunnableMethod @@ -374,6 +379,7 @@ CamerasChild::GetCaptureDevice(CaptureEngine aCapEngine, bool* scary) { LOG((__PRETTY_FUNCTION__)); + RefPtr deathGrip = this; nsCOMPtr runnable = mozilla::NewNonOwningRunnableMethod (this, &CamerasChild::SendGetCaptureDevice, aCapEngine, list_number); @@ -413,6 +419,7 @@ CamerasChild::AllocateCaptureDevice(CaptureEngine aCapEngine, const nsACString& aOrigin) { LOG((__PRETTY_FUNCTION__)); + RefPtr deathGrip = this; nsCString unique_id(unique_idUTF8); nsCString origin(aOrigin); nsCOMPtr runnable = @@ -444,6 +451,7 @@ CamerasChild::ReleaseCaptureDevice(CaptureEngine aCapEngine, const int capture_id) { LOG((__PRETTY_FUNCTION__)); + RefPtr deathGrip = this; nsCOMPtr runnable = mozilla::NewNonOwningRunnableMethod (this, &CamerasChild::SendReleaseCaptureDevice, aCapEngine, capture_id); @@ -491,6 +499,7 @@ CamerasChild::StartCapture(CaptureEngine aCapEngine, webrtcCaps.rawType, webrtcCaps.codecType, webrtcCaps.interlaced); + RefPtr deathGrip = this; nsCOMPtr runnable = mozilla::NewNonOwningRunnableMethod (this, &CamerasChild::SendStartCapture, aCapEngine, capture_id, capCap); @@ -502,6 +511,7 @@ int CamerasChild::StopCapture(CaptureEngine aCapEngine, const int capture_id) { LOG((__PRETTY_FUNCTION__)); + RefPtr deathGrip = this; nsCOMPtr runnable = mozilla::NewNonOwningRunnableMethod (this, &CamerasChild::SendStopCapture, aCapEngine, capture_id); @@ -567,6 +577,7 @@ CamerasChild::ShutdownParent() // Delete the parent actor. // CamerasChild (this) will remain alive and is only deleted by the // IPC layer when SendAllDone returns. + RefPtr deathGrip = this; nsCOMPtr deleteRunnable = mozilla::NewNonOwningRunnableMethod(this, &CamerasChild::SendAllDone); CamerasSingleton::Thread()->Dispatch(deleteRunnable, NS_DISPATCH_NORMAL); @@ -695,7 +706,7 @@ CamerasChild::~CamerasChild() { LOG(("~CamerasChild: %p", this)); - { + if (!CamerasSingleton::InShutdown()) { OffTheBooksMutexAutoLock lock(CamerasSingleton::Mutex()); // In normal circumstances we've already shut down and the // following does nothing. But on fatal IPC errors we will -- cgit v1.2.3