Bug 976171 - crash in mozilla::net::CacheIOThread::LoopOneLevel(unsigned int), r=michal
authorHonza Bambas <honzab.moz@firemni.cz>
Fri, 02 May 2014 20:15:15 +0200
changeset 181770 c69333201bc72986792810b9606ee4db5023e8d8
parent 181769 8a6a5bfdedc6b0abcf64100cbb8d4eeada5ef180
child 181771 acbdfd79dbb534f154fcdaa4c60738dcfc048308
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersmichal
bugs976171
milestone32.0a1
Bug 976171 - crash in mozilla::net::CacheIOThread::LoopOneLevel(unsigned int), r=michal
netwerk/cache2/CacheIOThread.cpp
--- a/netwerk/cache2/CacheIOThread.cpp
+++ b/netwerk/cache2/CacheIOThread.cpp
@@ -51,41 +51,50 @@ nsresult CacheIOThread::Init()
 
   return NS_OK;
 }
 
 nsresult CacheIOThread::Dispatch(nsIRunnable* aRunnable, uint32_t aLevel)
 {
   NS_ENSURE_ARG(aLevel < LAST_LEVEL);
 
+  // Runnable is always expected to be non-null, hard null-check bellow.
+  MOZ_ASSERT(aRunnable);
+
   MonitorAutoLock lock(mMonitor);
 
   if (mShutdown && (PR_GetCurrentThread() != mThread))
     return NS_ERROR_UNEXPECTED;
 
   return DispatchInternal(aRunnable, aLevel);
 }
 
 nsresult CacheIOThread::DispatchAfterPendingOpens(nsIRunnable* aRunnable)
 {
+  // Runnable is always expected to be non-null, hard null-check bellow.
+  MOZ_ASSERT(aRunnable);
+
   MonitorAutoLock lock(mMonitor);
 
   if (mShutdown && (PR_GetCurrentThread() != mThread))
     return NS_ERROR_UNEXPECTED;
 
   // Move everything from later executed OPEN level to the OPEN_PRIORITY level
   // where we post the (eviction) runnable.
   mEventQueue[OPEN_PRIORITY].AppendElements(mEventQueue[OPEN]);
   mEventQueue[OPEN].Clear();
 
   return DispatchInternal(aRunnable, OPEN_PRIORITY);
 }
 
 nsresult CacheIOThread::DispatchInternal(nsIRunnable* aRunnable, uint32_t aLevel)
 {
+  if (NS_WARN_IF(!aRunnable))
+    return NS_ERROR_NULL_POINTER;
+
   mMonitor.AssertCurrentThreadOwns();
 
   mEventQueue[aLevel].AppendElement(aRunnable);
   if (mLowestLevelWaiting > aLevel)
     mLowestLevelWaiting = aLevel;
 
   mMonitor.NotifyAll();