bug 197827 : fix a leak by making nsSHEntry use nsCOMArray. r=radha sr=alecf

This commit is contained in:
hpradhan%hotpop.com 2005-08-18 11:16:42 +00:00
Родитель 69374258dc
Коммит a6fe550fa7
2 изменённых файлов: 10 добавлений и 19 удалений

Просмотреть файл

@ -39,15 +39,6 @@ nsSHEntry::nsSHEntry()
nsSHEntry::~nsSHEntry()
{
// Release the references to any child entries...
PRInt32 i, childCount = mChildren.Count();
for (i=0; i<childCount; i++) {
nsISHEntry* child;
child = (nsISHEntry*) mChildren.ElementAt(i);
NS_IF_RELEASE(child);
}
mChildren.Clear();
}
@ -362,7 +353,7 @@ nsSHEntry::AddChild(nsISHEntry * aChild, PRInt32 aOffset)
NS_ENSURE_TRUE(aChild, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(aChild->SetParent(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;
}

Просмотреть файл

@ -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<nsIInputStream> mPostData;
nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
nsVoidArray mChildren;
nsCOMArray<nsISHEntry> mChildren;
PRUint32 mLoadType;
PRUint32 mID;
PRInt32 mScrollPositionX;