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

This commit is contained in:
dbaron@dbaron.org 2007-09-27 09:27:48 -07:00
Родитель 0926363321
Коммит c73c09fe83
1 изменённых файлов: 12 добавлений и 9 удалений

Просмотреть файл

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