Fix for bug 374449 (Most callers of nsIDocument::RemoveReference leak). r/sr=jst.

This commit is contained in:
peterv%propagandism.org 2007-03-20 17:39:25 +00:00
Родитель 003883eceb
Коммит 8d3c347199
6 изменённых файлов: 29 добавлений и 19 удалений

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

@ -613,7 +613,7 @@ public:
virtual void AddReference(void *aKey, nsISupports *aReference) = 0; virtual void AddReference(void *aKey, nsISupports *aReference) = 0;
virtual nsISupports *GetReference(void *aKey) = 0; virtual nsISupports *GetReference(void *aKey) = 0;
virtual already_AddRefed<nsISupports> RemoveReference(void *aKey) = 0; virtual void RemoveReference(void *aKey) = 0;
/** /**
* Set the container (docshell) for this document. * Set the container (docshell) for this document.

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

@ -719,11 +719,10 @@ nsContentUtils::doReparentContentWrapper(nsIContent *aNode,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (aOldDocument) { if (aOldDocument) {
nsCOMPtr<nsISupports> old_ref = aOldDocument->RemoveReference(aNode); nsCOMPtr<nsISupports> old_ref = aOldDocument->GetReference(aNode);
if (old_ref) { if (old_ref) {
// Transfer the reference from aOldDocument to aNewDocument // Transfer the reference from aOldDocument to aNewDocument
aOldDocument->RemoveReference(aNode);
aNewDocument->AddReference(aNode, old_ref); aNewDocument->AddReference(aNode, old_ref);
} }
} }

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

@ -4866,17 +4866,12 @@ nsDocument::GetReference(void *aKey)
return nsnull; return nsnull;
} }
already_AddRefed<nsISupports> void
nsDocument::RemoveReference(void *aKey) nsDocument::RemoveReference(void *aKey)
{ {
nsISupports* oldReference = nsnull;
if (mContentWrapperHash) { if (mContentWrapperHash) {
mContentWrapperHash->Get(aKey, &oldReference);
mContentWrapperHash->Remove(aKey); mContentWrapperHash->Remove(aKey);
} }
return oldReference;
} }
nsIScriptEventManager* nsIScriptEventManager*

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

@ -497,7 +497,7 @@ public:
virtual void FlushPendingNotifications(mozFlushType aType); virtual void FlushPendingNotifications(mozFlushType aType);
virtual void AddReference(void *aKey, nsISupports *aReference); virtual void AddReference(void *aKey, nsISupports *aReference);
virtual nsISupports *GetReference(void *aKey); virtual nsISupports *GetReference(void *aKey);
virtual already_AddRefed<nsISupports> RemoveReference(void *aKey); virtual void RemoveReference(void *aKey);
virtual nsIScriptEventManager* GetScriptEventManager(); virtual nsIScriptEventManager* GetScriptEventManager();
virtual void SetXMLDeclaration(const PRUnichar *aVersion, virtual void SetXMLDeclaration(const PRUnichar *aVersion,
const PRUnichar *aEncoding, const PRUnichar *aEncoding,

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

@ -432,15 +432,30 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep,
} }
} }
else if (nodeInfoManager) { else if (nodeInfoManager) {
nsCOMPtr<nsISupports> oldRef;
nsIDocument* oldDoc = aNode->GetOwnerDoc();
if (oldDoc) {
oldRef = oldDoc->GetReference(aNode);
if (oldRef) {
oldDoc->RemoveReference(aNode);
}
}
aNode->mNodeInfo.swap(newNodeInfo); aNode->mNodeInfo.swap(newNodeInfo);
nsIDocument* newDoc = aNode->GetOwnerDoc(); nsIDocument* newDoc = aNode->GetOwnerDoc();
nsPIDOMWindow* window = newDoc ? newDoc->GetInnerWindow() : nsnull; if (newDoc) {
if (window) { if (oldRef) {
nsCOMPtr<nsIEventListenerManager> elm; newDoc->AddReference(aNode, oldRef);
aNode->GetListenerManager(PR_FALSE, getter_AddRefs(elm)); }
if (elm) {
window->SetMutationListeners(elm->MutationListenerBits()); nsPIDOMWindow* window = newDoc->GetInnerWindow();
if (window) {
nsCOMPtr<nsIEventListenerManager> elm;
aNode->GetListenerManager(PR_FALSE, getter_AddRefs(elm));
if (elm) {
window->SetMutationListeners(elm->MutationListenerBits());
}
} }
} }

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

@ -779,11 +779,12 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mListenerManager) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mListenerManager)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSessionStorage) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSessionStorage)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDoc)
// Unlink any associated preserved wrapper. // Unlink any associated preserved wrapper.
if (tmp->mDoc) if (tmp->mDoc) {
tmp->mDoc->RemoveReference(tmp->mDoc.get()); tmp->mDoc->RemoveReference(tmp->mDoc.get());
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDoc)
}
// Unlink stuff from nsPIDOMWindow // Unlink stuff from nsPIDOMWindow
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChromeEventHandler) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChromeEventHandler)