Skip to content

Commit

Permalink
libc: avoid nesting of atexit handler calls
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nfeske committed Feb 5, 2025
1 parent 013a9e9 commit 5d9673c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion repos/libports/src/lib/libc/internal/atexit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 5d9673c

Please sign in to comment.