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
This commit is contained in:
tor%cs.brown.edu
2007-10-19 15:36:15 +00:00
parent 3667c35027
commit cbc0c0a8a1
3 changed files with 32 additions and 12 deletions

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;