aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2011-01-17 13:23:57 +0100
committerMartin Willi <martin@revosec.ch>2011-01-17 18:19:44 +0100
commitb94feb4b05625deeb6a49e43153ce7edd7802488 (patch)
treef2a3b6922280aa17cff8b1034edfaa1f68bc587b /src/libstrongswan
parentec8426a3499251892e7a222203fd939b22a88207 (diff)
downloadstrongswan-b94feb4b05625deeb6a49e43153ce7edd7802488.tar.bz2
strongswan-b94feb4b05625deeb6a49e43153ce7edd7802488.tar.xz
backtrace->contains_function takes multiple names, speeding up whitelist check drastically
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/utils/backtrace.c14
-rw-r--r--src/libstrongswan/utils/backtrace.h9
-rw-r--r--src/libstrongswan/utils/leak_detective.c19
3 files changed, 16 insertions, 26 deletions
diff --git a/src/libstrongswan/utils/backtrace.c b/src/libstrongswan/utils/backtrace.c
index a67245194..41224e8c2 100644
--- a/src/libstrongswan/utils/backtrace.c
+++ b/src/libstrongswan/utils/backtrace.c
@@ -132,10 +132,11 @@ static void log_(private_backtrace_t *this, FILE *file, bool detailed)
/**
* Implementation of backtrace_t.contains_function
*/
-static bool contains_function(private_backtrace_t *this, char *function)
+static bool contains_function(private_backtrace_t *this,
+ char *function[], int count)
{
#ifdef HAVE_DLADDR
- int i;
+ int i, j;
for (i = 0; i< this->frame_count; i++)
{
@@ -143,9 +144,12 @@ static bool contains_function(private_backtrace_t *this, char *function)
if (dladdr(this->frames[i], &info) && info.dli_sname)
{
- if (streq(info.dli_sname, function))
+ for (j = 0; j < count; j++)
{
- return TRUE;
+ if (streq(info.dli_sname, function[j]))
+ {
+ return TRUE;
+ }
}
}
}
@@ -179,7 +183,7 @@ backtrace_t *backtrace_create(int skip)
this->frame_count = frame_count;
this->public.log = (void(*)(backtrace_t*,FILE*,bool))log_;
- this->public.contains_function = (bool(*)(backtrace_t*, char *function))contains_function;
+ this->public.contains_function = (bool(*)(backtrace_t*, char *function[], int count))contains_function;
this->public.destroy = (void(*)(backtrace_t*))destroy;
return &this->public;
diff --git a/src/libstrongswan/utils/backtrace.h b/src/libstrongswan/utils/backtrace.h
index c6b0ec78f..e8ccfc1bd 100644
--- a/src/libstrongswan/utils/backtrace.h
+++ b/src/libstrongswan/utils/backtrace.h
@@ -41,12 +41,13 @@ struct backtrace_t {
void (*log)(backtrace_t *this, FILE *file, bool detailed);
/**
- * Check if the backtrace contains a frame in a specific function.
+ * Check if the backtrace contains a frame having a function in a list.
*
- * @param function name
- * @return TRUE if function is in the stack
+ * @param function name array
+ * @param number of elements in function array
+ * @return TRUE if one of the functions is in the stack
*/
- bool (*contains_function)(backtrace_t *this, char *function);
+ bool (*contains_function)(backtrace_t *this, char *function[], int count);
/**
* Destroy a backtrace instance.
diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c
index acd8b7c3a..a645610ca 100644
--- a/src/libstrongswan/utils/leak_detective.c
+++ b/src/libstrongswan/utils/leak_detective.c
@@ -233,22 +233,6 @@ char *whitelist[] = {
};
/**
- * check if a stack frame contains functions listed above
- */
-static bool is_whitelisted(backtrace_t *backtrace)
-{
- int i;
- for (i = 0; i < sizeof(whitelist)/sizeof(char*); i++)
- {
- if (backtrace->contains_function(backtrace, whitelist[i]))
- {
- return TRUE;
- }
- }
- return FALSE;
-}
-
-/**
* Report leaks at library destruction
*/
static void report(private_leak_detective_t *this, bool detailed)
@@ -260,7 +244,8 @@ static void report(private_leak_detective_t *this, bool detailed)
for (hdr = first_header.next; hdr != NULL; hdr = hdr->next)
{
- if (is_whitelisted(hdr->backtrace))
+ if (hdr->backtrace->contains_function(hdr->backtrace,
+ whitelist, countof(whitelist)))
{
whitelisted++;
}