Skip to content

Commit

Permalink
Fix heap pools to assert that the object being released is allocated. (
Browse files Browse the repository at this point in the history
…#22411)

The bitmap object pool has a corresponding assert.  The pool
implementations should not differ in behavior here.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 28, 2023
1 parent 141ffe5 commit 1609476
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/lib/support/Pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,25 +354,26 @@ class HeapObjectPool : public internal::Statistics, public internal::PoolCommon<
if (object != nullptr)
{
internal::HeapObjectListNode * node = mObjects.FindNode(object);
if (node != nullptr)
// Releasing an object that is not allocated indicates likely memory
// corruption; better to safe-crash than proceed at this point.
VerifyOrDie(node != nullptr);

node->mObject = nullptr;
Platform::Delete(object);

// The node needs to be released immediately if we are not in the middle of iteration.
// Otherwise cleanup is deferred until all iteration on this pool completes and it's safe to release nodes.
if (mObjects.mIterationDepth == 0)
{
node->mObject = nullptr;
Platform::Delete(object);

// The node needs to be released immediately if we are not in the middle of iteration.
// Otherwise cleanup is deferred until all iteration on this pool completes and it's safe to release nodes.
if (mObjects.mIterationDepth == 0)
{
node->Remove();
Platform::Delete(node);
}
else
{
mObjects.mHaveDeferredNodeRemovals = true;
}

DecreaseUsage();
node->Remove();
Platform::Delete(node);
}
else
{
mObjects.mHaveDeferredNodeRemovals = true;
}

DecreaseUsage();
}
}

Expand Down

0 comments on commit 1609476

Please sign in to comment.