[hackers] [scc] [libc] Fix exit() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 7 Mar 2017 22:24:33 +0100 (CET)

commit 3ddba6b6ed93c63e246397e08acdc39a2e1744a9
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Mar 7 20:31:56 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Mar 7 20:31:56 2017 +0100

    [libc] Fix exit()
    
    The functions registered at atexit() must be called in reverse
    order. This patch also protect against calling exit() from
    some of the atexit handler.

diff --git a/libc/src/exit.c b/libc/src/exit.c
index 09248ae..0712378 100644
--- a/libc/src/exit.c
+++ b/libc/src/exit.c
_AT_@ -9,8 +9,13 @@ void
 exit(int status)
 {
         void (**bp)(void);
+ int i;
 
- for (bp = _atexitf; bp < &_atexitf[_ATEXIT_MAX] && *bp; ++bp)
- (*bp)();
+ for (i = _ATEXIT_MAX-1; i >= 0; --i) {
+ if (bp = _atexit[i]) {
+ *_atexit[i] = NULL;
+ (*bp)();
+ }
+ }
         _Exit(status);
 }
Received on Tue Mar 07 2017 - 22:24:33 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 07 2017 - 22:36:18 CET