Bug 503638 OOM crash [@ PL_DHashTableOperate | _MD_CURRENT_THREAD] in nsCycleCollector
r=dbaron
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -1372,16 +1372,17 @@ private:
#ifdef DEBUG_CC
nsCString mNextEdgeName;
#endif
public:
GCGraphBuilder(GCGraph &aGraph,
nsCycleCollectionLanguageRuntime **aRuntimes);
~GCGraphBuilder();
+ bool Initialized();
PRUint32 Count() const { return mPtrToNodeMap.entryCount; }
#ifdef DEBUG_CC
PtrInfo* AddNode(void *s, nsCycleCollectionParticipant *aParticipant,
PRUint32 aLangID);
#else
PtrInfo* AddNode(void *s, nsCycleCollectionParticipant *aParticipant);
@@ -1425,16 +1426,22 @@ GCGraphBuilder::GCGraphBuilder(GCGraph &
}
GCGraphBuilder::~GCGraphBuilder()
{
if (mPtrToNodeMap.ops)
PL_DHashTableFinish(&mPtrToNodeMap);
}
+bool
+GCGraphBuilder::Initialized()
+{
+ return !!mPtrToNodeMap.ops;
+}
+
PtrInfo*
GCGraphBuilder::AddNode(void *s, nsCycleCollectionParticipant *aParticipant
IF_DEBUG_CC_PARAM(PRUint32 aLangID)
)
{
PtrToNodeEntry *e = static_cast<PtrToNodeEntry*>(PL_DHashTableOperate(&mPtrToNodeMap, s, PL_DHASH_ADD));
if (!e)
return nsnull;
@@ -2576,16 +2583,18 @@ nsCycleCollector::Collect(PRUint32 aTryC
PRBool
nsCycleCollector::BeginCollection()
{
if (mParams.mDoNothing)
return PR_FALSE;
GCGraphBuilder builder(mGraph, mRuntimes);
+ if (!builder.Initialized())
+ return PR_FALSE;
#ifdef COLLECT_TIME_DEBUG
PRTime now = PR_Now();
#endif
for (PRUint32 i = 0; i <= nsIProgrammingLanguage::MAX; ++i) {
if (mRuntimes[i])
mRuntimes[i]->BeginCycleCollection(builder);
}