diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index 23715d11f..f222ec318 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -283,8 +283,18 @@ public: } void clear_and_dispose(Disposer auto disposer) noexcept { - while (!empty()) { - disposer(&pop_front()); + 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); } }