Bug 732495 - clean up refcounting for nsXBLDocumentInfo creation to fix leak. r=smaug

This commit is contained in:
Andrew McCreight 2012-03-22 13:46:03 -07:00
Родитель 1e10331fe7
Коммит c735d40322
4 изменённых файлов: 12 добавлений и 25 удалений

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

@ -423,8 +423,13 @@ nsXBLContentSink::OnOpenContainer(const PRUnichar **aAtts,
bool ret = true;
if (aTagName == nsGkAtoms::bindings) {
ENSURE_XBL_STATE(mState == eXBL_InDocument);
mDocInfo = NS_NewXBLDocumentInfo(mDocument);
NS_ASSERTION(mDocument, "Must have a document!");
nsRefPtr<nsXBLDocumentInfo> info = new nsXBLDocumentInfo(mDocument);
// We keep a weak ref. We're creating a cycle between doc/binding manager/doc info.
mDocInfo = info;
if (!mDocInfo) {
mState = eXBL_Error;
return true;
@ -433,16 +438,14 @@ nsXBLContentSink::OnOpenContainer(const PRUnichar **aAtts,
mDocument->BindingManager()->PutXBLDocumentInfo(mDocInfo);
nsIURI *uri = mDocument->GetDocumentURI();
bool isChrome = false;
bool isRes = false;
uri->SchemeIs("chrome", &isChrome);
uri->SchemeIs("resource", &isRes);
mIsChromeOrResource = isChrome || isRes;
nsXBLDocumentInfo* info = mDocInfo;
NS_RELEASE(info); // We keep a weak ref. We've created a cycle between doc/binding manager/doc info.
mState = eXBL_InBindings;
}
else if (aTagName == nsGkAtoms::binding) {

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

@ -682,7 +682,8 @@ nsXBLDocumentInfo::ReadPrototypeBindings(nsIURI* aURI, nsXBLDocumentInfo** aDocI
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
nsRefPtr<nsXBLDocumentInfo> docInfo = NS_NewXBLDocumentInfo(doc);
NS_ASSERTION(doc, "Must have a document!");
nsRefPtr<nsXBLDocumentInfo> docInfo = new nsXBLDocumentInfo(doc);
while (1) {
PRUint8 flags;
@ -783,14 +784,3 @@ nsXBLDocumentInfo::GetScriptGlobalObject()
return mGlobalObject;
}
nsXBLDocumentInfo* NS_NewXBLDocumentInfo(nsIDocument* aDocument)
{
NS_PRECONDITION(aDocument, "Must have a document!");
nsXBLDocumentInfo* result;
result = new nsXBLDocumentInfo(aDocument);
NS_ADDREF(result);
return result;
}

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

@ -101,6 +101,4 @@ private:
nsRefPtr<nsXBLDocGlobalObject> mGlobalObject;
};
nsXBLDocumentInfo* NS_NewXBLDocumentInfo(nsIDocument* aDocument);
#endif

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

@ -1106,11 +1106,7 @@ nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement,
}
}
if (!info)
return NS_OK;
*aResult = info;
NS_IF_ADDREF(*aResult);
info.forget(aResult);
return NS_OK;
}