From 1760310123e6b86aecc545ae02b85ae8a7a8ab16 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 23 Apr 2024 15:00:24 +0200 Subject: [PATCH] Revert "util/IntrusiveList: allow the last disposer to destroy the IntrusiveList" This reverts commit 669cbcd25aec664c465907347601e48ab51c9aed ("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. --- src/util/IntrusiveList.hxx | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index f47ef266e..9a1a4eaef 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -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 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()); } }