From 03406c3659c828d1f3ceec5de6a725acc003c275 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Wed, 22 Mar 2000 02:21:33 +0000 Subject: [PATCH] Fix miscellaneous form element leaks. r=pollmann@netscape.com --- content/html/content/src/nsHTMLOptionElement.cpp | 10 ++++++---- content/html/content/src/nsHTMLSelectElement.cpp | 5 +++-- layout/html/content/src/nsHTMLOptionElement.cpp | 10 ++++++---- layout/html/content/src/nsHTMLSelectElement.cpp | 5 +++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index 71ff83d0eef..2aae9a5fe59 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -170,7 +170,7 @@ nsHTMLOptionElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) if (aIID.Equals(kIJSNativeInitializerIID)) { nsIJSNativeInitializer* tmp = this; *aInstancePtr = (void*) tmp; - AddRef(); + NS_ADDREF_THIS(); return NS_OK; } return NS_NOINTERFACE; @@ -372,7 +372,8 @@ nsHTMLOptionElement::GetIndex(PRInt32* aIndex) if (thisNode == thisOption) { res = NS_OK; *aIndex = i; - break; + NS_IF_RELEASE(thisOption); + break; // skips the release below, thus release above needed } NS_IF_RELEASE(thisOption); } @@ -636,10 +637,10 @@ nsHTMLOptionElement::Initialize(JSContext* aContext, JSString* jsstr = JS_ValueToString(aContext, argv[0]); if (nsnull != jsstr) { // Create a new text node and append it to the option - nsIContent* textNode; + nsCOMPtr textNode; nsITextContent* content; - result = NS_NewTextNode(&textNode); + result = NS_NewTextNode(getter_AddRefs(textNode)); if (NS_FAILED(result)) { return result; } @@ -657,6 +658,7 @@ nsHTMLOptionElement::Initialize(JSContext* aContext, return result; } + // this addrefs textNode: result = mInner.AppendChildTo(textNode, PR_FALSE); if (NS_FAILED(result)) { return result; diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index 3327d9b61ef..932f380867f 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -1189,6 +1189,7 @@ nsHTMLSelectElement::SetProperty(JSContext *aContext, res = mOptions->QueryInterface(kIJSScriptObjectIID, (void **)&optList); if (NS_SUCCEEDED(res) && optList) { res = optList->SetProperty(aContext, aObj, aID, aVp); + NS_RELEASE(optList); } } else { res = mInner.SetProperty(aContext, aObj, aID, aVp); @@ -1427,13 +1428,13 @@ nsHTMLOptionCollection::RemoveOption(nsIContent* aOption) PRInt32 nsHTMLOptionCollection::IndexOf(nsIContent* aOption) { - nsIDOMHTMLOptionElement* option; + nsCOMPtr option; if (mDirty && (nsnull != mSelect)) { GetOptions(); } if ((nsnull != aOption) && - NS_SUCCEEDED(aOption->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option))) { + NS_SUCCEEDED(aOption->QueryInterface(kIDOMHTMLOptionElementIID, getter_AddRefs(option)))) { return mElements.IndexOf(option); } return -1; diff --git a/layout/html/content/src/nsHTMLOptionElement.cpp b/layout/html/content/src/nsHTMLOptionElement.cpp index 71ff83d0eef..2aae9a5fe59 100644 --- a/layout/html/content/src/nsHTMLOptionElement.cpp +++ b/layout/html/content/src/nsHTMLOptionElement.cpp @@ -170,7 +170,7 @@ nsHTMLOptionElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) if (aIID.Equals(kIJSNativeInitializerIID)) { nsIJSNativeInitializer* tmp = this; *aInstancePtr = (void*) tmp; - AddRef(); + NS_ADDREF_THIS(); return NS_OK; } return NS_NOINTERFACE; @@ -372,7 +372,8 @@ nsHTMLOptionElement::GetIndex(PRInt32* aIndex) if (thisNode == thisOption) { res = NS_OK; *aIndex = i; - break; + NS_IF_RELEASE(thisOption); + break; // skips the release below, thus release above needed } NS_IF_RELEASE(thisOption); } @@ -636,10 +637,10 @@ nsHTMLOptionElement::Initialize(JSContext* aContext, JSString* jsstr = JS_ValueToString(aContext, argv[0]); if (nsnull != jsstr) { // Create a new text node and append it to the option - nsIContent* textNode; + nsCOMPtr textNode; nsITextContent* content; - result = NS_NewTextNode(&textNode); + result = NS_NewTextNode(getter_AddRefs(textNode)); if (NS_FAILED(result)) { return result; } @@ -657,6 +658,7 @@ nsHTMLOptionElement::Initialize(JSContext* aContext, return result; } + // this addrefs textNode: result = mInner.AppendChildTo(textNode, PR_FALSE); if (NS_FAILED(result)) { return result; diff --git a/layout/html/content/src/nsHTMLSelectElement.cpp b/layout/html/content/src/nsHTMLSelectElement.cpp index 3327d9b61ef..932f380867f 100644 --- a/layout/html/content/src/nsHTMLSelectElement.cpp +++ b/layout/html/content/src/nsHTMLSelectElement.cpp @@ -1189,6 +1189,7 @@ nsHTMLSelectElement::SetProperty(JSContext *aContext, res = mOptions->QueryInterface(kIJSScriptObjectIID, (void **)&optList); if (NS_SUCCEEDED(res) && optList) { res = optList->SetProperty(aContext, aObj, aID, aVp); + NS_RELEASE(optList); } } else { res = mInner.SetProperty(aContext, aObj, aID, aVp); @@ -1427,13 +1428,13 @@ nsHTMLOptionCollection::RemoveOption(nsIContent* aOption) PRInt32 nsHTMLOptionCollection::IndexOf(nsIContent* aOption) { - nsIDOMHTMLOptionElement* option; + nsCOMPtr option; if (mDirty && (nsnull != mSelect)) { GetOptions(); } if ((nsnull != aOption) && - NS_SUCCEEDED(aOption->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option))) { + NS_SUCCEEDED(aOption->QueryInterface(kIDOMHTMLOptionElementIID, getter_AddRefs(option)))) { return mElements.IndexOf(option); } return -1;