diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2014-03-11 20:48:48 +0100 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2014-03-11 20:48:48 +0100 |
commit | 15fb7904f4431a6e7c305fd08732458f7f885e7e (patch) | |
tree | c93b60ee813af70509f00f34e29ebec311762427 /src/libstrongswan/library.c | |
parent | 5313d2d78ca150515f7f5eb39801c100690b6b29 (diff) | |
download | vyos-strongswan-15fb7904f4431a6e7c305fd08732458f7f885e7e.tar.gz vyos-strongswan-15fb7904f4431a6e7c305fd08732458f7f885e7e.zip |
Imported Upstream version 5.1.2
Diffstat (limited to 'src/libstrongswan/library.c')
-rw-r--r-- | src/libstrongswan/library.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c index f2fa3e0aa..8472c30a5 100644 --- a/src/libstrongswan/library.c +++ b/src/libstrongswan/library.c @@ -22,6 +22,7 @@ #include <threading/thread.h> #include <utils/identification.h> #include <networking/host.h> +#include <collections/array.h> #include <collections/hashtable.h> #include <utils/backtrace.h> #include <selectors/traffic_selector.h> @@ -61,6 +62,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 */ @@ -75,7 +109,7 @@ void library_deinit() } detailed = lib->settings->get_bool(lib->settings, - "libstrongswan.leak_detective.detailed", TRUE); + "%s.leak_detective.detailed", TRUE, lib->ns); /* make sure the cache is clear before unloading plugins */ lib->credmgr->flush_cache(lib->credmgr, CERT_ANY); @@ -109,9 +143,11 @@ void library_deinit() lib->leak_detective->destroy(lib->leak_detective); } + arrays_deinit(); threads_deinit(); backtrace_deinit(); + free((void*)this->public.ns); free(this); lib = NULL; } @@ -201,7 +237,7 @@ static bool check_memwipe() /* * see header file */ -bool library_init(char *settings) +bool library_init(char *settings, const char *namespace) { private_library_t *this; printf_hook_t *pfh; @@ -217,6 +253,7 @@ bool library_init(char *settings) .public = { .get = _get, .set = _set, + .ns = strdup(namespace ?: "libstrongswan"), }, .ref = 1, ); @@ -224,9 +261,12 @@ bool library_init(char *settings) backtrace_init(); threads_init(); + arrays_init(); #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(); @@ -256,6 +296,9 @@ bool library_init(char *settings) this->objects = hashtable_create((hashtable_hash_t)hash, (hashtable_equals_t)equals, 4); this->public.settings = settings_create(settings); + /* all namespace settings may fall back to libstrongswan */ + lib->settings->add_fallback(lib->settings, lib->ns, "libstrongswan"); + this->public.hosts = host_resolver_create(); this->public.proposal = proposal_keywords_create(); this->public.caps = capabilities_create(); @@ -278,7 +321,7 @@ bool library_init(char *settings) } if (lib->settings->get_bool(lib->settings, - "libstrongswan.integrity_test", FALSE)) + "%s.integrity_test", FALSE, lib->ns)) { #ifdef INTEGRITY_TEST this->public.integrity = integrity_checker_create(CHECKSUM_LIBRARY); |