From 372cfcb2c6ea852d57708c2b19c7d9661c1dc284 Mon Sep 17 00:00:00 2001 From: "pollmann%netscape.com" Date: Wed, 23 Feb 2000 20:58:42 +0000 Subject: [PATCH] Bug 28691: Fix leaks, check for null, in code my implementation was based on r=harishd a=rickg git-svn-id: svn://10.0.0.236/trunk@61508 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsFileControlFrame.cpp | 32 +++++++++++-------- .../html/forms/src/nsFileControlFrame.cpp | 32 +++++++++++-------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 72d04711311..56d0338d345 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -312,6 +312,8 @@ nsFileControlFrame::SetInitialChildList(nsIPresContext* aPresContext, nsGfxTextControlFrame* nsFileControlFrame::GetTextControlFrame(nsIPresContext* aPresContext, nsIFrame* aStart) { + nsGfxTextControlFrame* result = nsnull; + // find the text control frame. nsIFrame* childFrame = nsnull; aStart->FirstChild(aPresContext, nsnull, &childFrame); @@ -319,16 +321,20 @@ nsFileControlFrame::GetTextControlFrame(nsIPresContext* aPresContext, nsIFrame* while (childFrame) { // see if the child is a text control nsCOMPtr content; - childFrame->GetContent(getter_AddRefs(content)); - nsIAtom* atom; - if (content->GetTag(atom) == NS_OK && atom == nsHTMLAtoms::input) { - nsString value; + nsresult res = childFrame->GetContent(getter_AddRefs(content)); + if (NS_SUCCEEDED(res) && content) { + nsCOMPtr atom; + res = content->GetTag(*getter_AddRefs(atom)); + if (NS_SUCCEEDED(res) && atom) { + if (atom.get() == nsHTMLAtoms::input) { - if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value)) { - value.ToUpperCase(); - nsString txt("TEXT"); - if (value == txt) { - return (nsGfxTextControlFrame*)childFrame; + // It's an input, is it a text input? + nsAutoString value; + if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value)) { + if (value.EqualsIgnoreCase("text")) { + result = (nsGfxTextControlFrame*)childFrame; + } + } } } } @@ -336,13 +342,13 @@ nsFileControlFrame::GetTextControlFrame(nsIPresContext* aPresContext, nsIFrame* // if not continue looking nsGfxTextControlFrame* frame = GetTextControlFrame(aPresContext, childFrame); if (frame) - return frame; + result = frame; - nsresult rv = childFrame->GetNextSibling(&childFrame); - NS_ASSERTION(rv == NS_OK,"failed to get next child"); + res = childFrame->GetNextSibling(&childFrame); + NS_ASSERTION(res == NS_OK,"failed to get next child"); } - return nsnull; + return result; } PRIntn diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index 72d04711311..56d0338d345 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -312,6 +312,8 @@ nsFileControlFrame::SetInitialChildList(nsIPresContext* aPresContext, nsGfxTextControlFrame* nsFileControlFrame::GetTextControlFrame(nsIPresContext* aPresContext, nsIFrame* aStart) { + nsGfxTextControlFrame* result = nsnull; + // find the text control frame. nsIFrame* childFrame = nsnull; aStart->FirstChild(aPresContext, nsnull, &childFrame); @@ -319,16 +321,20 @@ nsFileControlFrame::GetTextControlFrame(nsIPresContext* aPresContext, nsIFrame* while (childFrame) { // see if the child is a text control nsCOMPtr content; - childFrame->GetContent(getter_AddRefs(content)); - nsIAtom* atom; - if (content->GetTag(atom) == NS_OK && atom == nsHTMLAtoms::input) { - nsString value; + nsresult res = childFrame->GetContent(getter_AddRefs(content)); + if (NS_SUCCEEDED(res) && content) { + nsCOMPtr atom; + res = content->GetTag(*getter_AddRefs(atom)); + if (NS_SUCCEEDED(res) && atom) { + if (atom.get() == nsHTMLAtoms::input) { - if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value)) { - value.ToUpperCase(); - nsString txt("TEXT"); - if (value == txt) { - return (nsGfxTextControlFrame*)childFrame; + // It's an input, is it a text input? + nsAutoString value; + if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value)) { + if (value.EqualsIgnoreCase("text")) { + result = (nsGfxTextControlFrame*)childFrame; + } + } } } } @@ -336,13 +342,13 @@ nsFileControlFrame::GetTextControlFrame(nsIPresContext* aPresContext, nsIFrame* // if not continue looking nsGfxTextControlFrame* frame = GetTextControlFrame(aPresContext, childFrame); if (frame) - return frame; + result = frame; - nsresult rv = childFrame->GetNextSibling(&childFrame); - NS_ASSERTION(rv == NS_OK,"failed to get next child"); + res = childFrame->GetNextSibling(&childFrame); + NS_ASSERTION(res == NS_OK,"failed to get next child"); } - return nsnull; + return result; } PRIntn