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>
This commit is contained in:
parent
321e3ae2fb
commit
0be0680ab5
|
@ -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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue