Skip to content

Commit 1609476

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Fix heap pools to assert that the object being released is allocated. (#22411)
The bitmap object pool has a corresponding assert. The pool implementations should not differ in behavior here.
1 parent 141ffe5 commit 1609476

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/lib/support/Pool.h

+18-17
Original file line numberDiff line numberDiff line change
@@ -354,25 +354,26 @@ class HeapObjectPool : public internal::Statistics, public internal::PoolCommon<
354354
if (object != nullptr)
355355
{
356356
internal::HeapObjectListNode * node = mObjects.FindNode(object);
357-
if (node != nullptr)
357+
// Releasing an object that is not allocated indicates likely memory
358+
// corruption; better to safe-crash than proceed at this point.
359+
VerifyOrDie(node != nullptr);
360+
361+
node->mObject = nullptr;
362+
Platform::Delete(object);
363+
364+
// The node needs to be released immediately if we are not in the middle of iteration.
365+
// Otherwise cleanup is deferred until all iteration on this pool completes and it's safe to release nodes.
366+
if (mObjects.mIterationDepth == 0)
358367
{
359-
node->mObject = nullptr;
360-
Platform::Delete(object);
361-
362-
// The node needs to be released immediately if we are not in the middle of iteration.
363-
// Otherwise cleanup is deferred until all iteration on this pool completes and it's safe to release nodes.
364-
if (mObjects.mIterationDepth == 0)
365-
{
366-
node->Remove();
367-
Platform::Delete(node);
368-
}
369-
else
370-
{
371-
mObjects.mHaveDeferredNodeRemovals = true;
372-
}
373-
374-
DecreaseUsage();
368+
node->Remove();
369+
Platform::Delete(node);
375370
}
371+
else
372+
{
373+
mObjects.mHaveDeferredNodeRemovals = true;
374+
}
375+
376+
DecreaseUsage();
376377
}
377378
}
378379

0 commit comments

Comments
 (0)