Add prof_leak_error option

The option makes the process to exit with error code 1 if a memory leak
is detected. This is useful for implementing automated tools that rely
on leak detection.
This commit is contained in:
yunxu
2022-01-12 18:46:34 +08:00
committed by Alex Lapenkou
parent eafd2ac39f
commit b798fabdf7
8 changed files with 56 additions and 0 deletions

View File

@@ -1037,6 +1037,16 @@ prof_leakcheck(const prof_cnt_t *cnt_all, size_t leak_ngctx) {
1) ? "s" : "", leak_ngctx, (leak_ngctx != 1) ? "s" : "");
malloc_printf(
"<jemalloc>: Run jeprof on dump output for leak detail\n");
if (opt_prof_leak_error) {
malloc_printf(
"<jemalloc>: Exiting with error code because memory"
" leaks were detected\n");
/*
* Use _exit() with underscore to avoid calling atexit()
* and entering endless cycle.
*/
_exit(1);
}
}
#endif
}