summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2011-11-05 10:05:40 +0100
committerSylvain Munaut <tnt@246tNt.com>2011-11-13 20:25:19 +0100
commit0be0680ab5198dfd2170e5c894256b8c329676a8 (patch)
treed2a9282c8bf4b6937d034c448a71bad1ea824456
parent321e3ae2fb16a364e8bde96ddf47f5cff661d3df (diff)
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 <jolly@eversberg.eu> Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r--src/host/layer23/src/mobile/main.c42
1 files 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;
}