aboutsummaryrefslogtreecommitdiff
path: root/prototype.c
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2013-03-18 09:44:25 +0100
committerPetr Machata <pmachata@redhat.com>2013-03-18 09:44:25 +0100
commitf70812ec281a829ca7a758337aacec58eca41550 (patch)
tree3ee71f31954d2db29babc4acb55080cad28efe05 /prototype.c
parenta43b2a0206419a31691d61f37b3a6789204ba503 (diff)
downloadltrace-f70812ec281a829ca7a758337aacec58eca41550.tar.gz
Fix exit before parsing options
- The function destroy_global_config was called from normal_exit even if init_global_config hadn't been called before, such as when ltrace was run with no command line arguments. This led to crashes. We avoided similar crashes due to exit from init_global_config by calling _Exit instead. - Instead, schedule execution of destroy_global_config only after it is known that init_global_config was successful. Replace the clumsy _Exit calls again by plain exit.
Diffstat (limited to 'prototype.c')
-rw-r--r--prototype.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/prototype.c b/prototype.c
index 23fc7a5..60aa5c6 100644
--- a/prototype.c
+++ b/prototype.c
@@ -621,6 +621,13 @@ protolib_cache_protolib(struct protolib_cache *cache,
return rc;
}
+static void
+destroy_global_config(void)
+{
+ protolib_cache_destroy(&g_protocache);
+ protolib_destroy(&legacy_typedefs);
+}
+
void
init_global_config(void)
{
@@ -641,22 +648,13 @@ init_global_config(void)
fprintf(stderr,
"Couldn't initialize aliases `addr' and `file'.\n");
- /* Since global config was not yet initialized, do an
- * early exit. */
- fflush(stderr);
- _Exit(1);
+ exit(1);
}
if (protolib_cache_init(&g_protocache, NULL) < 0) {
fprintf(stderr, "Couldn't init prototype cache\n");
- fflush(stderr);
- _Exit(1);
+ exit(1);
}
-}
-void
-destroy_global_config(void)
-{
- protolib_cache_destroy(&g_protocache);
- protolib_destroy(&legacy_typedefs);
+ atexit(destroy_global_config);
}