Bug 992313 - Keep track of registered idle observers so we don't call into a freed pointer. r=roc

This commit is contained in:
Reuben Morais 2014-04-21 14:18:53 -03:00
parent 9564bd368c
commit 202914c96c
2 changed files with 16 additions and 2 deletions

View File

@ -51,7 +51,6 @@
#include "nsIMemoryInfoDumper.h"
#include "nsIMutable.h"
#include "nsIObserverService.h"
#include "nsIObserver.h"
#include "nsIScriptSecurityManager.h"
#include "nsServiceManagerUtils.h"
#include "nsStyleSheetService.h"
@ -1282,6 +1281,8 @@ ContentChild::ActorDestroy(ActorDestroyReason why)
mAlertObservers.Clear();
mIdleObservers.Clear();
nsCOMPtr<nsIConsoleService> svc(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
if (svc) {
svc->UnregisterListener(mConsoleListener);
@ -1660,6 +1661,7 @@ ContentChild::AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS)
// Make sure aObserver isn't released while we wait for the parent
aObserver->AddRef();
SendAddIdleObserver(reinterpret_cast<uint64_t>(aObserver), aIdleTimeInS);
mIdleObservers.PutEntry(aObserver);
}
void
@ -1668,6 +1670,7 @@ ContentChild::RemoveIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS)
MOZ_ASSERT(aObserver, "null idle observer");
SendRemoveIdleObserver(reinterpret_cast<uint64_t>(aObserver), aIdleTimeInS);
aObserver->Release();
mIdleObservers.RemoveEntry(aObserver);
}
bool
@ -1676,7 +1679,11 @@ ContentChild::RecvNotifyIdleObserver(const uint64_t& aObserver,
const nsString& aTimeStr)
{
nsIObserver* observer = reinterpret_cast<nsIObserver*>(aObserver);
observer->Observe(nullptr, aTopic.get(), aTimeStr.get());
if (mIdleObservers.Contains(observer)) {
observer->Observe(nullptr, aTopic.get(), aTimeStr.get());
} else {
NS_WARNING("Received notification for an idle observer that was removed.");
}
return true;
}

View File

@ -10,8 +10,13 @@
#include "mozilla/Attributes.h"
#include "mozilla/dom/PContentChild.h"
#include "mozilla/dom/ipc/Blob.h"
#include "nsHashKeys.h"
#include "nsIObserver.h"
#include "nsTHashtable.h"
#include "nsWeakPtr.h"
struct ChromePackage;
class nsIDOMBlob;
class nsIObserver;
@ -298,6 +303,8 @@ private:
InfallibleTArray<nsAutoPtr<AlertObserver> > mAlertObservers;
nsRefPtr<ConsoleListener> mConsoleListener;
nsTHashtable<nsPtrHashKey<nsIObserver>> mIdleObservers;
/**
* An ID unique to the process containing our corresponding
* content parent.