From 2a5407199140d8728bfc017383ad0dc41627ea1b Mon Sep 17 00:00:00 2001 From: "hpradhan%hotpop.com" Date: Thu, 18 Aug 2005 11:16:42 +0000 Subject: [PATCH] bug 197827 : fix a leak by making nsSHEntry use nsCOMArray. r=radha sr=alecf --- docshell/shistory/src/nsSHEntry.cpp | 25 ++++++++----------------- docshell/shistory/src/nsSHEntry.h | 4 ++-- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/docshell/shistory/src/nsSHEntry.cpp b/docshell/shistory/src/nsSHEntry.cpp index 0908c5a058d7..d2ac5f5685b4 100644 --- a/docshell/shistory/src/nsSHEntry.cpp +++ b/docshell/shistory/src/nsSHEntry.cpp @@ -39,15 +39,6 @@ nsSHEntry::nsSHEntry() nsSHEntry::~nsSHEntry() { - // Release the references to any child entries... - PRInt32 i, childCount = mChildren.Count(); - for (i=0; iSetParent(this), NS_ERROR_FAILURE); - PRInt32 childCount = mChildren.Count(); + // // Bug 52670: Ensure children are added in order. // @@ -372,12 +363,10 @@ nsSHEntry::AddChild(nsISHEntry * aChild, PRInt32 aOffset) // // Assert that aOffset will not be so high as to grow us a lot. // - NS_ASSERTION(aOffset < (childCount + 1023), "Large frames array!\n"); + NS_ASSERTION(aOffset < (mChildren.Count()+1023), "Large frames array!\n"); // This implicitly extends the array to include aOffset - mChildren.ReplaceElementAt(aChild, aOffset); - - NS_ADDREF(aChild); + mChildren.ReplaceObjectAt(aChild, aOffset); return NS_OK; } @@ -386,10 +375,9 @@ NS_IMETHODIMP nsSHEntry::RemoveChild(nsISHEntry * aChild) { NS_ENSURE_TRUE(aChild, NS_ERROR_FAILURE); - PRBool childRemoved = mChildren.RemoveElement((void *)aChild); + PRBool childRemoved = mChildren.RemoveObject(aChild); if (childRemoved) { aChild->SetParent(nsnull); - NS_RELEASE(aChild); } return NS_OK; } @@ -399,7 +387,10 @@ NS_IMETHODIMP nsSHEntry::GetChildAt(PRInt32 aIndex, nsISHEntry ** aResult) { NS_ENSURE_ARG_POINTER(aResult); - *aResult = (nsISHEntry*) mChildren.SafeElementAt(aIndex); + *aResult = nsnull; + if (aIndex >= 0 && aIndex < mChildren.Count()) { + *aResult = mChildren[aIndex]; + } NS_IF_ADDREF(*aResult); return NS_OK; } diff --git a/docshell/shistory/src/nsSHEntry.h b/docshell/shistory/src/nsSHEntry.h index 0321844a02a4..8479f1832d08 100644 --- a/docshell/shistory/src/nsSHEntry.h +++ b/docshell/shistory/src/nsSHEntry.h @@ -25,8 +25,8 @@ // Helper Classes #include "nsCOMPtr.h" +#include "nsCOMArray.h" #include "nsString.h" -#include "nsVoidArray.h" // Interfaces needed #include "nsIDOMDocument.h" @@ -61,7 +61,7 @@ private: nsString mTitle; nsCOMPtr mPostData; nsCOMPtr mLayoutHistoryState; - nsVoidArray mChildren; + nsCOMArray mChildren; PRUint32 mLoadType; PRUint32 mID; PRInt32 mScrollPositionX;