From b295256ea2f71a4fe3b16e0348b907f6ef73167b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 01:14:26 +0000 Subject: r2640: valgrind does a great job on some types of memory leaks, but is slow and can't properly handle leaks of doubly linked lists which we use a lot (as the memory is always reachable). Even with --show-reachable its hard to track leaks down sometimes. I realised that talloc does have the necessary information to track these, and by using the cascading property of the new talloc it can report on leaks in a much more succinct fashion than valgrind can. I have added a new samba option --leak-check that applies to all Samba tools. When enabled it prints a leak report summarising all top level contexts that are present when the program exits. A typical report looks like this: talloc report on 'null_context' (total 1071 bytes in 52 blocks) iconv(CP850,UTF8) contains 43 bytes in 3 blocks UNNAMED contains 24 bytes in 1 blocks UNNAMED contains 24 bytes in 1 blocks dcesrv_init contains 604 bytes in 26 blocks server_service contains 120 bytes in 6 blocks UNNAMED contains 24 bytes in 1 blocks UNNAMED contains 24 bytes in 1 blocks server_service contains 104 bytes in 4 blocks server_context contains 12 bytes in 2 blocks iconv(UTF8,UTF-16LE) contains 46 bytes in 3 blocks iconv(UTF-16LE,UTF8) contains 46 bytes in 3 blocks the numbers are recursive summaries for all the memory hanging off each context. this option is not thread safe when used, but the code is thread safe if the option is not given, so I don't think thats a problem. (This used to be commit 96d33d36a5639e7fc46b14a470ccac674d87c62a) --- source4/lib/cmdline/popt_common.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source4/lib/cmdline') diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c index e2deb5db96..f98c460642 100644 --- a/source4/lib/cmdline/popt_common.c +++ b/source4/lib/cmdline/popt_common.c @@ -34,7 +34,7 @@ */ -enum {OPT_OPTION=1}; +enum {OPT_OPTION=1,OPT_LEAK_CHECK=2}; static struct cmdline_auth_info cmdline_auth_info; @@ -116,6 +116,10 @@ static void popt_common_callback(poptContext con, exit(1); } break; + + case OPT_LEAK_CHECK: + talloc_enable_leak_check(); + break; } } @@ -132,10 +136,11 @@ struct poptOption popt_common_connection[] = { struct poptOption popt_common_samba[] = { { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, - { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, - { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" }, - { "option", 0, POPT_ARG_STRING, NULL, OPT_OPTION, "Set smb.conf option from command line", "name=value" }, + { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, + { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" }, + { "option", 0, POPT_ARG_STRING, NULL, OPT_OPTION, "Set smb.conf option from command line", "name=value" }, { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files", "LOGFILEBASE" }, + { "leak-check", 0, POPT_ARG_NONE, NULL, OPT_LEAK_CHECK, "enable talloc leak checking", NULL }, POPT_TABLEEND }; -- cgit