Skip to content

Commit

Permalink
util/IntrusiveList: allow the last disposer to destroy the IntrusiveList
Browse files Browse the repository at this point in the history
Fixes a use-after-free bug in Co::MultiAwaitable::SetReady() when the
last callback frees the Co::MultiAwaitable owner.
  • Loading branch information
MaxKellermann committed Apr 10, 2024
1 parent 5b4b83d commit 0b59adb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/util/IntrusiveList.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,18 @@ public:
}

void clear_and_dispose(Disposer<value_type> 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);
}
}

Expand Down

0 comments on commit 0b59adb

Please sign in to comment.