diff options
author | Martin Willi <martin@revosec.ch> | 2013-10-16 10:37:38 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2013-11-06 10:30:59 +0100 |
commit | a426851f6362f8d1d6cbecd133ef39a831b4ea2a (patch) | |
tree | d5ae0d9f3be281bcfa479f134cba53634d568d2c /src/libstrongswan/library.c | |
parent | 9ae1140118837d981d7566e8dbdca3f0ebc3466b (diff) | |
download | strongswan-a426851f6362.tar.bz2 strongswan-a426851f6362.tar.xz |
leak-detective: Use callback functions to report leaks and usage information
This is more flexible than printing reports to a FILE.
Diffstat (limited to 'src/libstrongswan/library.c')
-rw-r--r-- | src/libstrongswan/library.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c index f2fa3e0aa..72fc2fa44 100644 --- a/src/libstrongswan/library.c +++ b/src/libstrongswan/library.c @@ -61,6 +61,39 @@ struct private_library_t { */ library_t *lib = NULL; +#ifdef LEAK_DETECTIVE +/** + * Default leak report callback + */ +static void report_leaks(void *user, int count, size_t bytes, + backtrace_t *bt, bool detailed) +{ + fprintf(stderr, "%zu bytes total, %d allocations, %zu bytes average:\n", + bytes, count, bytes / count); + bt->log(bt, stderr, detailed); +} + +/** + * Default leak report summary callback + */ +static void sum_leaks(void* user, int count, size_t bytes, int whitelisted) +{ + switch (count) + { + case 0: + fprintf(stderr, "No leaks detected"); + break; + case 1: + fprintf(stderr, "One leak detected"); + break; + default: + fprintf(stderr, "%d leaks detected, %zu bytes", count, bytes); + break; + } + fprintf(stderr, ", %d suppressed by whitelist\n", whitelisted); +} +#endif /* LEAK_DETECTIVE */ + /** * Deinitialize library */ @@ -227,6 +260,8 @@ bool library_init(char *settings) #ifdef LEAK_DETECTIVE lib->leak_detective = leak_detective_create(); + lib->leak_detective->set_report_cb(lib->leak_detective, + report_leaks, sum_leaks, NULL); #endif /* LEAK_DETECTIVE */ pfh = printf_hook_create(); |