Skip to content

atexit handlers get executed in reverse order upon termination and don't get executed at all on abort - #155

Open
rosenrost wants to merge 2 commits into
freemint:masterfrom
rosenrost:fix/atexit
Open

rosenrost wants to merge 2 commits into
freemint:masterfrom
rosenrost:fix/atexit

Conversation

@rosenrost

Copy link
Copy Markdown
Contributor
  1. The C standard requires the functions registered with atexit() to be called in the reverse order of their registration. exit() called them in registration order. This also affects the C++ destructors that are registered via atexit() in __main().
  2. abort() called exit() and therefore ran all atexit() handlers and C++ destructors, which must not happen on abnormal termination. Use _exit() instead.

The C standard requires the functions registered with atexit() to be
called in the reverse order of their registration. exit() called them
in registration order. This also affects the C++ destructors that are
registered via atexit() in __main().

The handlers are now called by index, so a handler that registers
another handler (which may realloc() the array) no longer breaks the
loop.
abort() called exit() and therefore ran all atexit() handlers and C++
destructors, which must not happen on abnormal termination. Use _exit()
instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant