Bug 1387058 - Part 1: Clear the static pointer when no more AudioStreams. r=jwwang, a=lizzard
authorChun-Min Chang <chun.m.chang@gmail.com>
Fri, 04 Aug 2017 14:20:48 +0800
changeset 421660 abfc6cba67470808a1a4a0bb73598d6cb052f749
parent 421659 a4605a256ecda20c88baf1499ab0fc6a3d32fdff
child 421661 2e414f305aabc2795cd4e62704559e86eb402710
push id7736
push userryanvm@gmail.com
push dateMon, 11 Sep 2017 15:47:51 +0000
treeherdermozilla-beta@94cf7f1ee06b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang, lizzard
bugs1387058
milestone56.0
Bug 1387058 - Part 1: Clear the static pointer when no more AudioStreams. r=jwwang, a=lizzard
dom/media/AudioNotificationReceiver.cpp
--- a/dom/media/AudioNotificationReceiver.cpp
+++ b/dom/media/AudioNotificationReceiver.cpp
@@ -49,16 +49,20 @@ AudioNotificationReceiver::Register(Audi
 AudioNotificationReceiver::Unregister(AudioStream* aAudioStream)
 {
   MOZ_ASSERT(XRE_IsContentProcess());
 
   StaticMutexAutoLock lock(sMutex);
   MOZ_ASSERT(!sSubscribers->IsEmpty(), "No subscriber.");
 
   sSubscribers->RemoveElement(aAudioStream);
+  if (sSubscribers->IsEmpty()) {
+    // Clear the static pointer here to prevent memory leak.
+    sSubscribers = nullptr;
+  }
 
   ANR_LOG("The AudioStream: %p is unregistered successfully.", aAudioStream);
 }
 
 /* static */ void
 AudioNotificationReceiver::NotifyDefaultDeviceChanged()
 {
   MOZ_ASSERT(XRE_IsContentProcess());