From 0be0680ab5198dfd2170e5c894256b8c329676a8 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 5 Nov 2011 10:05:40 +0100 Subject: [PATCH] host/mobile: Adding memory leak debugging When mobile exits, a list of allocated memory chunks are dumped to stderr. This helps to find talloc_free / msgb_free leaks. During process, a SIGUSR1 or SIGUSR2 can be used to dump currently allocated memory chunks. Written-by: Andreas Eversberg Signed-off-by: Sylvain Munaut --- src/host/layer23/src/mobile/main.c | 42 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c index 6e743df1..3da8e89f 100644 --- a/src/host/layer23/src/mobile/main.c +++ b/src/host/layer23/src/mobile/main.c @@ -147,13 +147,30 @@ void sighandler(int sigset) fprintf(stderr, "Signal %d received.\n", sigset); - /* in case there is a lockup during exit */ - signal(SIGINT, SIG_DFL); - signal(SIGHUP, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGPIPE, SIG_DFL); - - osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL); + switch (sigset) { + case SIGINT: + /* If another signal is received afterwards, the program + * is terminated without finishing shutdown process. + */ + signal(SIGINT, SIG_DFL); + signal(SIGHUP, SIG_DFL); + signal(SIGTERM, SIG_DFL); + signal(SIGPIPE, SIG_DFL); + signal(SIGABRT, SIG_DFL); + signal(SIGUSR1, SIG_DFL); + signal(SIGUSR2, SIG_DFL); + + osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL); + break; + case SIGABRT: + /* in case of abort, we want to obtain a talloc report + * and then return to the caller, who will abort the process + */ + case SIGUSR1: + case SIGUSR2: + talloc_report_full(l23_ctx, stderr); + break; + } } int main(int argc, char **argv) @@ -176,6 +193,7 @@ int main(int argc, char **argv) log_set_all_filter(stderr_target, 1); l23_ctx = talloc_named_const(NULL, 1, "layer2 context"); + msgb_set_talloc_ctx(l23_ctx); handle_options(argc, argv); @@ -214,6 +232,9 @@ int main(int argc, char **argv) signal(SIGHUP, sighandler); signal(SIGTERM, sighandler); signal(SIGPIPE, sighandler); + signal(SIGABRT, sighandler); + signal(SIGUSR1, sighandler); + signal(SIGUSR2, sighandler); if (daemonize) { printf("Running as daemon\n"); @@ -231,5 +252,12 @@ int main(int argc, char **argv) l23_app_exit(); + if (config_file) + talloc_free(config_file); + if (config_dir) + talloc_free(config_dir); + + talloc_report_full(l23_ctx, stderr); + return 0; } -- 2.11.4.GIT