From cbc0c0a8a1329dd2a55d64ba2eed84c6515b01f5 Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Fri, 19 Oct 2007 15:36:15 +0000 Subject: [PATCH] Bug 399289 - leak of nsBaseURLParser with svg paint. r+sr+a=dbaron git-svn-id: svn://10.0.0.236/trunk@237916 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/style/nsRuleNode.cpp | 13 ++++++++----- mozilla/layout/style/nsStyleStruct.cpp | 23 ++++++++++++++++++++--- mozilla/layout/style/nsStyleStruct.h | 8 ++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index 2026795ecd6..9cf4f783ed7 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -4335,17 +4335,19 @@ SetSVGPaint(const nsCSSValuePair& aValue, const nsStyleSVGPaint& parentPaint, nsStyleSVGPaint& aResult, nsStyleSVGPaintType aInitialPaintType, PRBool& aInherited) { + nscolor color; + if (aValue.mXValue.GetUnit() == eCSSUnit_Inherit) { aResult = parentPaint; aInherited = PR_TRUE; } else if (aValue.mXValue.GetUnit() == eCSSUnit_None) { - aResult.mType = eStyleSVGPaintType_None; + aResult.SetType(eStyleSVGPaintType_None); } else if (aValue.mXValue.GetUnit() == eCSSUnit_Initial) { - aResult.mType = aInitialPaintType; + aResult.SetType(aInitialPaintType); aResult.mPaint.mColor = NS_RGB(0, 0, 0); aResult.mFallbackColor = NS_RGB(0, 0, 0); } else if (aValue.mXValue.GetUnit() == eCSSUnit_URL) { - aResult.mType = eStyleSVGPaintType_Server; + aResult.SetType(eStyleSVGPaintType_Server); aResult.mPaint.mPaintServer = aValue.mXValue.GetURLValue(); NS_IF_ADDREF(aResult.mPaint.mPaintServer); if (aValue.mYValue.GetUnit() == eCSSUnit_None) { @@ -4354,8 +4356,9 @@ SetSVGPaint(const nsCSSValuePair& aValue, const nsStyleSVGPaint& parentPaint, NS_ASSERTION(aValue.mYValue.GetUnit() != eCSSUnit_Inherit, "cannot inherit fallback colour"); SetColor(aValue.mYValue, NS_RGB(0, 0, 0), aPresContext, aContext, aResult.mFallbackColor, aInherited); } - } else if (SetColor(aValue.mXValue, parentPaint.mPaint.mColor, aPresContext, aContext, aResult.mPaint.mColor, aInherited)) { - aResult.mType = eStyleSVGPaintType_Color; + } else if (SetColor(aValue.mXValue, parentPaint.mPaint.mColor, aPresContext, aContext, color, aInherited)) { + aResult.SetType(eStyleSVGPaintType_Color); + aResult.mPaint.mColor = color; } } diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index fb00a02d90a..4f46da09a96 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -829,15 +829,30 @@ nsChangeHint nsStyleSVGReset::MaxDifference() #endif // nsStyleSVGPaint implementation -nsStyleSVGPaint::~nsStyleSVGPaint() { +nsStyleSVGPaint::~nsStyleSVGPaint() +{ if (mType == eStyleSVGPaintType_Server) { NS_IF_RELEASE(mPaint.mPaintServer); - } + } +} + +void +nsStyleSVGPaint::SetType(nsStyleSVGPaintType aType) +{ + if (mType == eStyleSVGPaintType_Server) { + this->~nsStyleSVGPaint(); + new (this) nsStyleSVGPaint(); + } + mType = aType; } nsStyleSVGPaint& nsStyleSVGPaint::operator=(const nsStyleSVGPaint& aOther) { - mType = aOther.mType; + if (this == &aOther) + return *this; + + SetType(aOther.mType); + mFallbackColor = aOther.mFallbackColor; if (mType == eStyleSVGPaintType_Server) { mPaint.mPaintServer = aOther.mPaint.mPaintServer; @@ -1263,6 +1278,8 @@ nsStyleContentData& nsStyleContentData::operator=(const nsStyleContentData& aOth if (this == &aOther) return *this; this->~nsStyleContentData(); + new (this) nsStyleContentData(); + mType = aOther.mType; if (mType == eStyleContentType_Image) { mContent.mImage = aOther.mContent.mImage; diff --git a/mozilla/layout/style/nsStyleStruct.h b/mozilla/layout/style/nsStyleStruct.h index d48b5851fa7..0c2b9c92c9c 100644 --- a/mozilla/layout/style/nsStyleStruct.h +++ b/mozilla/layout/style/nsStyleStruct.h @@ -1218,7 +1218,7 @@ struct nsStyleColumn : public nsStyleStruct { #ifdef MOZ_SVG enum nsStyleSVGPaintType { - eStyleSVGPaintType_None = 0, + eStyleSVGPaintType_None = 1, eStyleSVGPaintType_Color, eStyleSVGPaintType_Server }; @@ -1232,9 +1232,9 @@ struct nsStyleSVGPaint } mPaint; nscolor mFallbackColor; - // empty constructor to keep Sun compiler happy - nsStyleSVGPaint() {} - ~nsStyleSVGPaint(); + nsStyleSVGPaint() : mType(nsStyleSVGPaintType(0)) { mPaint.mPaintServer = nsnull; } + ~nsStyleSVGPaint(); + void SetType(nsStyleSVGPaintType aType); nsStyleSVGPaint& operator=(const nsStyleSVGPaint& aOther); PRBool operator==(const nsStyleSVGPaint& aOther) const;