From 7e59447e8d0ce748659a392d15adace0377f1ac4 Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Wed, 21 Jul 2004 21:20:14 +0000 Subject: [PATCH] Don't allocate and leak selectors that we don't need. b=252510 r+sr=bzbarsky --- content/html/style/src/nsCSSParser.cpp | 26 ++++++++++++++------------ layout/style/nsCSSParser.cpp | 26 ++++++++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/content/html/style/src/nsCSSParser.cpp b/content/html/style/src/nsCSSParser.cpp index 0beda334dc3a..0bf45141ed3d 100644 --- a/content/html/style/src/nsCSSParser.cpp +++ b/content/html/style/src/nsCSSParser.cpp @@ -2325,16 +2325,16 @@ void CSSParserImpl::ParseNegatedSimpleSelector(PRInt32& aDataMask, return; } aParsingStatus = SELECTOR_PARSING_ENDED_OK; - nsCSSSelector* newSel = new nsCSSSelector(); - if (nsnull == aSelector.mNegations && - ((eCSSToken_ID == mToken.mType) || - mToken.IsSymbol('.') || - mToken.IsSymbol(':') || - mToken.IsSymbol('['))) { - // ID, class and attribute selectors and pseudo-classes are stored in - // the first mNegations attached to a selector - aSelector.mNegations = newSel; + if (!aSelector.mNegations) { + aSelector.mNegations = new nsCSSSelector(); + if (!aSelector.mNegations) { + aErrorCode = NS_ERROR_OUT_OF_MEMORY; + aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR; + return; + } } + // ID, class and attribute selectors and pseudo-classes are stored in + // the first mNegations attached to a selector if (eCSSToken_ID == mToken.mType) { // #id ParseIDSelector(aDataMask, *aSelector.mNegations, aParsingStatus, aErrorCode); } @@ -2349,10 +2349,12 @@ void CSSParserImpl::ParseNegatedSimpleSelector(PRInt32& aDataMask, } else { // then it should be a type element or universal selector - if (nsnull == aSelector.mNegations) { - aSelector.mNegations = newSel; + nsCSSSelector *newSel = new nsCSSSelector(); + if (!newSel) { + aErrorCode = NS_ERROR_OUT_OF_MEMORY; + aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR; + return; } - newSel = new nsCSSSelector(); nsCSSSelector* negations = aSelector.mNegations; while (nsnull != negations->mNegations) { negations = negations->mNegations; diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 0beda334dc3a..0bf45141ed3d 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -2325,16 +2325,16 @@ void CSSParserImpl::ParseNegatedSimpleSelector(PRInt32& aDataMask, return; } aParsingStatus = SELECTOR_PARSING_ENDED_OK; - nsCSSSelector* newSel = new nsCSSSelector(); - if (nsnull == aSelector.mNegations && - ((eCSSToken_ID == mToken.mType) || - mToken.IsSymbol('.') || - mToken.IsSymbol(':') || - mToken.IsSymbol('['))) { - // ID, class and attribute selectors and pseudo-classes are stored in - // the first mNegations attached to a selector - aSelector.mNegations = newSel; + if (!aSelector.mNegations) { + aSelector.mNegations = new nsCSSSelector(); + if (!aSelector.mNegations) { + aErrorCode = NS_ERROR_OUT_OF_MEMORY; + aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR; + return; + } } + // ID, class and attribute selectors and pseudo-classes are stored in + // the first mNegations attached to a selector if (eCSSToken_ID == mToken.mType) { // #id ParseIDSelector(aDataMask, *aSelector.mNegations, aParsingStatus, aErrorCode); } @@ -2349,10 +2349,12 @@ void CSSParserImpl::ParseNegatedSimpleSelector(PRInt32& aDataMask, } else { // then it should be a type element or universal selector - if (nsnull == aSelector.mNegations) { - aSelector.mNegations = newSel; + nsCSSSelector *newSel = new nsCSSSelector(); + if (!newSel) { + aErrorCode = NS_ERROR_OUT_OF_MEMORY; + aParsingStatus = SELECTOR_PARSING_STOPPED_ERROR; + return; } - newSel = new nsCSSSelector(); nsCSSSelector* negations = aSelector.mNegations; while (nsnull != negations->mNegations) { negations = negations->mNegations;