Revert "util/IntrusiveList: allow the last disposer to destroy the IntrusiveList"
This reverts commit 669cbcd25a
("util/IntrusiveList: allow the last disposer to destroy the
IntrusiveList"). It was bad because it could lead to off-by-one crash
bugs when the last item was removed inside the previous item's
disposer.
We need a different solution for the other crash bug that was fixed by
the reverted commit.
This commit is contained in:
parent
c8ed28e9c6
commit
1760310123
@ -293,20 +293,12 @@ public:
|
||||
|
||||
/**
|
||||
* Like clear(), but invoke a disposer function on each item.
|
||||
*
|
||||
* The disposer is not allowed to destruct the list.
|
||||
*/
|
||||
void clear_and_dispose(Disposer<value_type> auto disposer) noexcept {
|
||||
bool is_empty = empty();
|
||||
|
||||
while (!is_empty) {
|
||||
auto *item = &pop_front();
|
||||
|
||||
/* by checking empty() before invoking the
|
||||
disposer, it is possible for the disposer
|
||||
to destroy this IntrusiveList in the last
|
||||
call */
|
||||
is_empty = empty();
|
||||
|
||||
disposer(item);
|
||||
while (!empty()) {
|
||||
disposer(&pop_front());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user