Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix HeapObjectPool node leaks. (#20943)
Leaking scenario 1 (which was discovered in practice): An iteration on a pool that removes the element it's iterating and then does a Loop::Break. In that case we would break out of the loop in ForEachNode before setting anyReleased to true, which would cause the cleanup code to not run when the iteration depth went to 0 and the node to leak. This might have been fixed by reordering the setting of anyReleased and the break from the loop, except: Leaking scenario 2: Outer iteration iterates over the whole pool. When iterating the last element of the pool, it starts an inner iteration, which releases all but that last element. Then the two iterations complete. In this situation, the inner iteration would have anyReleased true, but not do any cleanup because it's a nested iteration, while the outer iteration would have anyReleased false (because the releases all happened behind its cursor, so it did not see any of them) and hence would not do any cleanup either. The fix is to just keep track of the "we need to do post-iteration cleanup" state in a member.
- Loading branch information