Bug 736761 - Don't crash if images are discarded after XPCOM shutdown. r=joe
authorJustin Lebar <justin.lebar@gmail.com>
Sun, 18 Mar 2012 09:56:00 -0400
changeset 93577 4ce96dfc2c16b5b4956bdc33efba6587cf6b9090
parent 93576 2906d8671454e1e412c5d0c3b91e40f43d075dc4
child 93578 edfcadccf600d4d242c6a0e2fc4ecf53e088343a
push id160
push userlsblakk@mozilla.com
push dateFri, 13 Jul 2012 18:18:57 +0000
treeherdermozilla-release@228ba1a111fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs736761
milestone14.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 736761 - Don't crash if images are discarded after XPCOM shutdown. r=joe
image/src/DiscardTracker.cpp
--- a/image/src/DiscardTracker.cpp
+++ b/image/src/DiscardTracker.cpp
@@ -148,22 +148,22 @@ DiscardTracker::Initialize()
 
   Preferences::AddUintVarCache(&sMaxDecodedImageKB,
                               "image.mem.max_decoded_image_kb",
                               50 * 1024);
 
   // Create the timer.
   sTimer = do_CreateInstance("@mozilla.org/timer;1");
 
+  // Mark us as initialized
+  sInitialized = true;
+
   // Read the timeout pref and start the timer.
   ReloadTimeout();
 
-  // Mark us as initialized
-  sInitialized = true;
-
   return NS_OK;
 }
 
 /**
  * Read the discard timeout from about:config.
  */
 void
 DiscardTracker::ReloadTimeout()
@@ -189,19 +189,22 @@ DiscardTracker::ReloadTimeout()
 }
 
 /**
  * Enables the timer. No-op if the timer is already running.
  */
 nsresult
 DiscardTracker::EnableTimer()
 {
-  // Nothing to do if the timer's already on.
-  if (sTimerOn)
+  // Nothing to do if the timer's already on or we haven't yet been
+  // initialized.  !sTimer probably means we've shut down, so just ignore that,
+  // too.
+  if (sTimerOn || !sInitialized || !sTimer)
     return NS_OK;
+
   sTimerOn = true;
 
   // Activate the timer.  Have it call us back in (sMinDiscardTimeoutMs / 2)
   // ms, so that an image is discarded between sMinDiscardTimeoutMs and
   // (3/2 * sMinDiscardTimeoutMs) ms after it's unlocked.
   return sTimer->InitWithFuncCallback(TimerCallback,
                                       nsnull,
                                       sMinDiscardTimeoutMs / 2,
@@ -210,17 +213,17 @@ DiscardTracker::EnableTimer()
 
 /*
  * Disables the timer. No-op if the timer isn't running.
  */
 void
 DiscardTracker::DisableTimer()
 {
   // Nothing to do if the timer's already off.
-  if (!sTimerOn)
+  if (!sTimerOn || !sTimer)
     return;
   sTimerOn = false;
 
   // Deactivate
   sTimer->Cancel();
 }
 
 /**