libc: avoid nesting of atexit handler calls

In some situations, atexit handlers perform I/O (e.g., closing a file),
which entails the handling of signals. Should SIGTERM be pending, the
handling of this signal will in turn trigger the execution of atexit
handlers. To break this cycle, this patch removes atexit handlers from
the list before executing them. So no atexit handler is entered more
than once.

Fixes #5444
This commit is contained in:
Norman Feske 2025-02-05 14:21:21 +01:00 committed by Christian Helmuth
parent 9795f264aa
commit d2adfa150b

View File

@ -111,8 +111,8 @@ struct Libc::Atexit : Noncopyable
if (!handler_ptr)
return false;
handler_ptr->execute();
_handlers.remove(handler_ptr);
handler_ptr->execute();
destroy(_alloc, handler_ptr);
return true;
};