Skip to content

Commit

Permalink
Bug 1841368, don't leak the old AttrArray::Impl, r=peterv
Browse files Browse the repository at this point in the history
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Jul 18, 2023
1 parent bf7598b commit 9a5f82b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions dom/base/AttrArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ void AttrArray::Compact() {
return;
}

Impl* impl = mImpl.release();
impl = static_cast<Impl*>(
realloc(impl, Impl::AllocationSizeForAttributes(impl->mAttrCount)));
MOZ_ASSERT(impl, "failed to reallocate to a smaller buffer!");
Impl* oldImpl = mImpl.release();
Impl* impl = static_cast<Impl*>(
realloc(oldImpl, Impl::AllocationSizeForAttributes(oldImpl->mAttrCount)));
if (!impl) {
mImpl.reset(oldImpl);
return;
}
impl->mCapacity = impl->mAttrCount;
mImpl.reset(impl);
}
Expand Down Expand Up @@ -314,9 +317,12 @@ bool AttrArray::GrowBy(uint32_t aGrowSize) {
Impl::AllocationSizeForAttributes(capacity.value()));

const bool needToInitialize = !mImpl;
Impl* newImpl =
static_cast<Impl*>(realloc(mImpl.release(), sizeInBytes.value()));
NS_ENSURE_TRUE(newImpl, false);
Impl* oldImpl = mImpl.release();
Impl* newImpl = static_cast<Impl*>(realloc(oldImpl, sizeInBytes.value()));
if (!newImpl) {
mImpl.reset(oldImpl);
return false;
}

mImpl.reset(newImpl);

Expand Down

0 comments on commit 9a5f82b

Please sign in to comment.