From afd1471cb71bf8b50008d1bdc3c83f579c053fa4 Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Fri, 25 Mar 2005 04:09:13 +0000 Subject: [PATCH] Clean up GetImportantRule and null-check for out-of-memory case to bulletproof against null dereference topcrash. b=287504 r+sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@171191 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/style/nsCSSStyleRule.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mozilla/layout/style/nsCSSStyleRule.cpp b/mozilla/layout/style/nsCSSStyleRule.cpp index 7ab0d98b99b..ce1c9cb0df2 100644 --- a/mozilla/layout/style/nsCSSStyleRule.cpp +++ b/mozilla/layout/style/nsCSSStyleRule.cpp @@ -854,6 +854,9 @@ NS_IMPL_ISUPPORTS1(CSSImportantRule, nsIStyleRule) NS_IMETHODIMP CSSImportantRule::MapRuleInfoInto(nsRuleData* aRuleData) { + // Check this at runtime because it might be hit in some out-of-memory cases. + NS_ENSURE_TRUE(mDeclaration->HasImportantData(), NS_ERROR_UNEXPECTED); + return mDeclaration->MapImportantRuleInfoInto(aRuleData); } @@ -1363,17 +1366,25 @@ nsCSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const already_AddRefed CSSStyleRuleImpl::GetImportantRule(void) { - if (!mImportantRule && mDeclaration->HasImportantData()) { - mImportantRule = new CSSImportantRule(mDeclaration); - NS_IF_ADDREF(mImportantRule); + if (!mDeclaration->HasImportantData()) { + NS_ASSERTION(!mImportantRule, "immutable, so should be no important rule"); + return nsnull; } - NS_IF_ADDREF(mImportantRule); + + if (!mImportantRule) { + mImportantRule = new CSSImportantRule(mDeclaration); + if (!mImportantRule) + return nsnull; + NS_ADDREF(mImportantRule); + } + NS_ADDREF(mImportantRule); return mImportantRule; } NS_IMETHODIMP CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const { +// XXX What about inner, etc. return nsCSSRule::GetStyleSheet(aSheet); }