broke if registered more than 32 atexit functions; from Chris Torek
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 15 Nov 1990 04:50:24 +0000 (20:50 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 15 Nov 1990 04:50:24 +0000 (20:50 -0800)
SCCS-vsn: lib/libc/stdlib/atexit.c 5.2

usr/src/lib/libc/stdlib/atexit.c

index 6840270..38242f4 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)atexit.c   5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)atexit.c   5.2 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stddef.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <stddef.h>
@@ -28,10 +28,11 @@ atexit(fn)
 
        if ((p = __atexit) == NULL)
                __atexit = p = &__atexit0;
 
        if ((p = __atexit) == NULL)
                __atexit = p = &__atexit0;
-       if (p->ind >= ATEXIT_SIZE) {
+       else if (p->ind >= ATEXIT_SIZE) {
                if ((p = malloc(sizeof(*p))) == NULL)
                        return (-1);
                if ((p = malloc(sizeof(*p))) == NULL)
                        return (-1);
-               __atexit->next = p;
+               p->ind = 0;
+               p->next = __atexit;
                __atexit = p;
        }
        p->fns[p->ind++] = fn;
                __atexit = p;
        }
        p->fns[p->ind++] = fn;