Always delete the old content array so that we run destructors. b=397022 r+sr=bzbarsky a=roc

git-svn-id: svn://10.0.0.236/trunk@236756 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbaron%dbaron.org 2007-09-27 16:27:48 +00:00
parent 94f24de901
commit 5ea7455586

View File

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