From c73c09fe8330f539bd9f466d06aa296e72c29d18 Mon Sep 17 00:00:00 2001 From: "dbaron@dbaron.org" Date: Thu, 27 Sep 2007 09:27:48 -0700 Subject: [PATCH] Always delete the old content array so that we run destructors. b=397022 r+sr=bzbarsky a=roc --- layout/style/nsStyleStruct.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index c98edd17e306..b903ecb86b7b 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1402,17 +1402,20 @@ nsChangeHint nsStyleContent::MaxDifference() nsresult nsStyleContent::AllocateContents(PRUint32 aCount) { - if (aCount != mContentCount) { - DELETE_ARRAY_IF(mContents); - if (aCount) { - mContents = new nsStyleContentData[aCount]; - if (! mContents) { - mContentCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } + // We need to run the destructors of the elements of mContents, so we + // delete and reallocate even if aCount == mContentCount. (If + // nsStyleContentData had its members private and managed their + // ownership on setting, we wouldn't need this, but that seems + // unnecessary at this point.) + DELETE_ARRAY_IF(mContents); + if (aCount) { + mContents = new nsStyleContentData[aCount]; + if (! mContents) { + mContentCount = 0; + return NS_ERROR_OUT_OF_MEMORY; } - mContentCount = aCount; } + mContentCount = aCount; return NS_OK; }