From 3a6ef3e3c19be59aadd3d337ae8b107e4c5aa259 Mon Sep 17 00:00:00 2001 From: kristerw Date: Wed, 8 Aug 2007 01:05:34 +0000 Subject: Keep track of atexit functions that are added while processing atexit functions, to ensure that the new functions will be called. --- lib/libc/stdlib/atexit.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/libc/stdlib') diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c index 8f66406aa6d..a9f12d0c2ad 100644 --- a/lib/libc/stdlib/atexit.c +++ b/lib/libc/stdlib/atexit.c @@ -1,4 +1,4 @@ -/* $NetBSD: atexit.c,v 1.18 2007/08/08 00:51:18 kristerw Exp $ */ +/* $NetBSD: atexit.c,v 1.19 2007/08/08 01:05:34 kristerw Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: atexit.c,v 1.18 2007/08/08 00:51:18 kristerw Exp $"); +__RCSID("$NetBSD: atexit.c,v 1.19 2007/08/08 01:05:34 kristerw Exp $"); #endif /* LIBC_SCCS and not lint */ #include "reentrant.h" @@ -191,9 +191,11 @@ __cxa_finalize(void *dso) * When the depth 1 caller sees those, it will simply unlink them * for us. */ +again: for (prevp = &atexit_handler_stack; (ah = (*prevp)) != NULL;) { if (dso == NULL || dso == ah->ah_dso || ah->ah_atexit == NULL) { if (ah->ah_atexit != NULL) { + void *p = atexit_handler_stack; if (ah->ah_dso != NULL) { cxa_func = ah->ah_cxa_atexit; ah->ah_cxa_atexit = NULL; @@ -203,6 +205,9 @@ __cxa_finalize(void *dso) ah->ah_atexit = NULL; (*atexit_func)(); } + /* Restart if new atexit handler was added. */ + if (p != atexit_handler_stack) + goto again; } if (call_depth == 1) { -- cgit