summaryrefslogtreecommitdiffstats
path: root/libdimension/error.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-09-30 12:29:08 -0400
committerTavian Barnes <tavianator@gmail.com>2010-09-30 17:19:39 -0400
commit32ccbb213b2a2d419581690d42611c375c3d22cf (patch)
tree1cdfd44c2936b0aa3d96ca54fbe30dab3d0a4c0e /libdimension/error.c
parent312387496ec8f30b50dcb21f47e74e4eb135c63b (diff)
downloaddimension-32ccbb213b2a2d419581690d42611c375c3d22cf.tar.xz
Fix behaviour when the error handler itself calls dmnsn_error().
Diffstat (limited to 'libdimension/error.c')
-rw-r--r--libdimension/error.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/libdimension/error.c b/libdimension/error.c
index 11b4805..721b45c 100644
--- a/libdimension/error.c
+++ b/libdimension/error.c
@@ -133,14 +133,22 @@ void dmnsn_set_fatal_error_fn(dmnsn_fatal_error_fn *fatal)
}
}
+/* Prevent infinite recursion if the fatal error function itself calls
+ dmnsn_error() */
+static __thread bool dmnsn_tl_exiting = false;
+
static void
dmnsn_default_fatal_error_fn()
{
dmnsn_backtrace(stderr);
- if (dmnsn_is_main_thread()) {
+ if (dmnsn_tl_exiting) {
+ abort();
+ } else if (dmnsn_is_main_thread()) {
exit(EXIT_FAILURE);
} else {
+ dmnsn_tl_exiting = true;
+
int *ret = malloc(sizeof(int)); /* Don't use dmnsn_malloc */
if (ret)
*ret = 1;