aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2014-04-01 10:30:13 +0200
committerTobias Brunner <tobias@strongswan.org>2014-04-03 09:44:26 +0200
commitadc11574876dc486fc3aa7d6bbd50405c50a96b8 (patch)
tree7f2bfe01f37a604fa7288035acc0927dbf132ecd /src
parent7a61bf9032dab58956ee6ad72986b1bc1a642668 (diff)
downloadstrongswan-adc11574876dc486fc3aa7d6bbd50405c50a96b8.tar.bz2
strongswan-adc11574876dc486fc3aa7d6bbd50405c50a96b8.tar.xz
leak-detective: LEAK_DETECTIVE_DISABLE completely disables LD
If lib->leak_detective is non-null some code parts (e.g. the plugin loader) assume LD is actually used.
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/library.c7
-rw-r--r--src/libstrongswan/utils/leak_detective.c15
-rw-r--r--src/libstrongswan/utils/leak_detective.h18
3 files changed, 23 insertions, 17 deletions
diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c
index 8472c30a5..c5bb4cd93 100644
--- a/src/libstrongswan/library.c
+++ b/src/libstrongswan/library.c
@@ -265,8 +265,11 @@ bool library_init(char *settings, const char *namespace)
#ifdef LEAK_DETECTIVE
lib->leak_detective = leak_detective_create();
- lib->leak_detective->set_report_cb(lib->leak_detective,
- report_leaks, sum_leaks, NULL);
+ if (lib->leak_detective)
+ {
+ lib->leak_detective->set_report_cb(lib->leak_detective,
+ report_leaks, sum_leaks, NULL);
+ }
#endif /* LEAK_DETECTIVE */
pfh = printf_hook_create();
diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c
index 82eadcb97..af29e2100 100644
--- a/src/libstrongswan/utils/leak_detective.c
+++ b/src/libstrongswan/utils/leak_detective.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Tobias Brunner
+ * Copyright (C) 2013-2014 Tobias Brunner
* Copyright (C) 2006-2013 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -973,17 +973,20 @@ leak_detective_t *leak_detective_create()
},
);
+ if (getenv("LEAK_DETECTIVE_DISABLE") != NULL)
+ {
+ free(this);
+ return NULL;
+ }
+
lock = spinlock_create();
thread_disabled = thread_value_create(NULL);
init_static_allocations();
- if (getenv("LEAK_DETECTIVE_DISABLE") == NULL)
+ if (register_hooks())
{
- if (register_hooks())
- {
- enable_leak_detective();
- }
+ enable_leak_detective();
}
return &this->public;
}
diff --git a/src/libstrongswan/utils/leak_detective.h b/src/libstrongswan/utils/leak_detective.h
index 3fd0b8c93..ca70067d4 100644
--- a/src/libstrongswan/utils/leak_detective.h
+++ b/src/libstrongswan/utils/leak_detective.h
@@ -50,9 +50,7 @@ typedef void (*leak_detective_summary_cb_t)(void* user, int count, size_t bytes,
int whitelisted);
/**
- * Leak detective finds leaks and bad frees using malloc hooks.
- *
- * Currently leaks are reported to stderr on destruction.
+ * Leak detective finds leaks and invalid frees using malloc hooks.
*
* @todo Build an API for leak detective, allowing leak enumeration, statistics
* and dynamic whitelisting.
@@ -62,13 +60,12 @@ struct leak_detective_t {
/**
* Report leaks to the registered callback functions.
*
- * @param detailed TRUE to resolve line/filename of leak (slow)
+ * @param detailed TRUE to resolve line/filename of leaks (slow)
*/
void (*report)(leak_detective_t *this, bool detailed);
/**
- * Report current memory usage to out.
- * Set callback functions invoked during a report().
+ * Set callback functions invoked when report() is called.
*
* @param cb callback invoked for each detected leak
* @param scb summary callback invoked at end of report
@@ -78,11 +75,11 @@ struct leak_detective_t {
leak_detective_summary_cb_t scb, void *user);
/**
- * Report current memory usage using a callbacks.
+ * Report current memory usage using callback functions.
*
* @param cb callback invoked for each allocation
* @param scb summary callback invoked at end of usage report
- * @param user user data supplied to callbacks
+ * @param user user data to supply to callbacks
*/
void (*usage)(leak_detective_t *this, leak_detective_report_cb_t cb,
leak_detective_summary_cb_t scb, void *user);
@@ -109,7 +106,10 @@ struct leak_detective_t {
};
/**
- * Create a leak_detective instance.
+ * Create a leak_detective instance, unless the LEAK_DETECTIVE_DISABLE
+ * environment variable is set.
+ *
+ * @return leak detective instance
*/
leak_detective_t *leak_detective_create();