diff --git a/sources/abort.c b/sources/abort.c index be1aa40..73b0b09 100644 --- a/sources/abort.c +++ b/sources/abort.c @@ -1,6 +1,8 @@ #include +#include void abort(void) { - exit(-1); + /* abnormal termination: unlike exit(), atexit() handlers must not be called */ + _exit(-1); } diff --git a/sources/exit.c b/sources/exit.c index 5ddccb3..bdc78ad 100644 --- a/sources/exit.c +++ b/sources/exit.c @@ -15,9 +15,9 @@ int _num_at_exit = 0; void exit(int status) { - /* first: call all atexit-registered func's */ - for(; _num_at_exit; --_num_at_exit) - (*_at_exit++) (); + /* first: call all atexit-registered func's, in reverse order of registration */ + while (_num_at_exit > 0) + (*_at_exit[--_num_at_exit]) (); /* second: close all files */ /* unneeded here, since handles are unbuffered */