OSDN Git Service

If realloc failed, we'd lose the pointer to the exit function table.
authorManuel Novoa III <mjn3@codepoet.org>
Sun, 2 Nov 2003 08:29:10 +0000 (08:29 -0000)
committerManuel Novoa III <mjn3@codepoet.org>
Sun, 2 Nov 2003 08:29:10 +0000 (08:29 -0000)
libc/stdlib/atexit.c

index 8b04e8a..ab124a0 100644 (file)
@@ -96,13 +96,14 @@ int atexit(aefuncp func)
 #ifdef __UCLIBC_DYNAMIC_ATEXIT__
        /* If we are out of function table slots, make some more */
        if (__exit_slots < __exit_count+1) {
-           __exit_function_table=realloc(__exit_function_table, 
-                   (__exit_slots+20)*sizeof(struct exit_function));
-           if (__exit_function_table==NULL) {
+           efp=realloc(__exit_function_table, 
+                                       (__exit_slots+20)*sizeof(struct exit_function));
+           if (efp==NULL) {
                UNLOCK;
                __set_errno(ENOMEM);
                return -1;
            }
+               __exit_function_table = efp;
            __exit_slots+=20;
        }
 #else
@@ -138,13 +139,14 @@ int on_exit(oefuncp func, void *arg)
 #ifdef __UCLIBC_DYNAMIC_ATEXIT__
        /* If we are out of function table slots, make some more */
        if (__exit_slots < __exit_count+1) {
-           __exit_function_table=realloc(__exit_function_table, 
-                   (__exit_slots+20)*sizeof(struct exit_function));
-           if (__exit_function_table==NULL) {
+           efp=realloc(__exit_function_table, 
+                                       (__exit_slots+20)*sizeof(struct exit_function));
+           if (efp==NULL) {
                UNLOCK;
                __set_errno(ENOMEM);
                return -1;
            }
+               __exit_function_table=efp;
            __exit_slots+=20;
        }
 #else