Bug 1387058 - part1: Clear the static pointer when no more AudioStreams; r=jwwang
authorChun-Min Chang <chun.m.chang@gmail.com>
Fri, 04 Aug 2017 14:20:48 +0800
changeset 422364 357a94f6484f6aafc305fcb643686e0b8863597b
parent 422363 f257d10ebc4a5df96e1228cd47e807c954e76656
child 422365 cde7d3637eeee95d3787500ff689075ac4831ab1
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1387058
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1387058 - part1: Clear the static pointer when no more AudioStreams; r=jwwang
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());