Bug 893242 - Part 2: Make sContentParents a StaticAutoPtr. r=khuey

This eliminates a static constructor, which is good.  It also avoids a
problem at shutdown: If we leak a ContentParent and we destroy
sContentParents atexit, then sContentParents will assert that it's not
empty and cause test failures.
This commit is contained in:
Justin Lebar 2013-07-17 14:31:10 -07:00
parent eacb45e46d
commit 21412f80a2
2 changed files with 12 additions and 4 deletions

View File

@ -205,7 +205,7 @@ MemoryReportRequestParent::~MemoryReportRequestParent()
nsDataHashtable<nsStringHashKey, ContentParent*>* ContentParent::sAppContentParents;
nsTArray<ContentParent*>* ContentParent::sNonAppContentParents;
nsTArray<ContentParent*>* ContentParent::sPrivateContent;
LinkedList<ContentParent> ContentParent::sContentParents;
StaticAutoPtr<LinkedList<ContentParent> > ContentParent::sContentParents;
// This is true when subprocess launching is enabled. This is the
// case between StartUp() and ShutDown() or JoinAllSubprocesses().
@ -515,7 +515,11 @@ ContentParent::GetAll(nsTArray<ContentParent*>& aArray)
{
aArray.Clear();
for (ContentParent* cp = sContentParents.getFirst(); cp;
if (!sContentParents) {
return;
}
for (ContentParent* cp = sContentParents->getFirst(); cp;
cp = cp->getNext()) {
aArray.AppendElement(cp);
}
@ -1074,7 +1078,10 @@ ContentParent::ContentParent(mozIApplication* aApp,
MOZ_ASSERT(!!aApp + aIsForBrowser + aIsForPreallocated <= 1);
// Insert ourselves into the global linked list of ContentParent objects.
sContentParents.insertBack(this);
if (!sContentParents) {
sContentParents = new LinkedList<ContentParent>();
}
sContentParents->insertBack(this);
if (aApp) {
aApp->GetManifestURL(mAppManifestURL);

View File

@ -17,6 +17,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/HalTypes.h"
#include "mozilla/LinkedList.h"
#include "mozilla/StaticPtr.h"
#include "nsFrameMessageManager.h"
#include "nsIObserver.h"
@ -180,7 +181,7 @@ private:
static nsDataHashtable<nsStringHashKey, ContentParent*> *sAppContentParents;
static nsTArray<ContentParent*>* sNonAppContentParents;
static nsTArray<ContentParent*>* sPrivateContent;
static LinkedList<ContentParent> sContentParents;
static StaticAutoPtr<LinkedList<ContentParent> > sContentParents;
static void JoinProcessesIOThread(const nsTArray<ContentParent*>* aProcesses,
Monitor* aMonitor, bool* aDone);