From 63da1ccbd0af26b4edaa6fc9f04775564cbb6a56 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 1 Sep 2005 02:40:12 +0000 Subject: [PATCH] Make sure to null out the weak parent ptr in session history entries as needed. Bug 305181, r=bryner, sr=jst git-svn-id: svn://10.0.0.236/trunk@179451 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/shistory/src/nsSHEntry.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mozilla/docshell/shistory/src/nsSHEntry.cpp b/mozilla/docshell/shistory/src/nsSHEntry.cpp index e7a1dbce12c..361ca62a568 100644 --- a/mozilla/docshell/shistory/src/nsSHEntry.cpp +++ b/mozilla/docshell/shistory/src/nsSHEntry.cpp @@ -99,8 +99,20 @@ nsSHEntry::nsSHEntry(const nsSHEntry &other) { } +PR_STATIC_CALLBACK(PRBool) +ClearParentPtr(nsISHEntry* aEntry, void* /* aData */) +{ + if (aEntry) { + aEntry->SetParent(nsnull); + } + return PR_TRUE; +} + nsSHEntry::~nsSHEntry() { + // Since we never really remove kids from SHEntrys, we need to null + // out the mParent pointers on all our kids. + mChildren.EnumerateForwards(ClearParentPtr, nsnull); mChildren.Clear(); RemoveDocumentObserver(); if (mContentViewer) @@ -469,6 +481,15 @@ nsSHEntry::AddChild(nsISHEntry * aChild, PRInt32 aOffset) // NS_ASSERTION(aOffset < (mChildren.Count()+1023), "Large frames array!\n"); + if (aOffset < mChildren.Count()) { + nsISHEntry* oldChild = mChildren.ObjectAt(aOffset); + if (oldChild && oldChild != aChild) { + NS_ERROR("Adding child where we already have a child? " + "This will likely misbehave"); + oldChild->SetParent(nsnull); + } + } + // This implicitly extends the array to include aOffset mChildren.ReplaceObjectAt(aChild, aOffset);