Skip to content

Commit 8eea280

Browse files
committed
leak-detective: Use hashtable to cache ignored/whitelisted backtraces
Checking for whitelisted functions in every backtrace is not very efficient. And because OpenSSL 1.1 does no proper cleanup anymore until the process is terminated there are now a lot more "leaks" to ignore. For instance, in the openssl-ikev2/rw-cert scenario, just starting and stopping the daemon (test vectors are checked) now causes 3594 whitelisted leaks compared to the 849 before. This prolonged the shutdown of the daemon on each guest in every scenario, amounting to multiple seconds of additional runtime for every affected scenario. But even with this patch there is still some overhead, compared to running the scenarios on jessie.
1 parent 0f7055b commit 8eea280

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/libstrongswan/utils/leak_detective.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ static int print_traces(private_leak_detective_t *this,
679679
int leaks = 0;
680680
memory_header_t *hdr;
681681
enumerator_t *enumerator;
682-
hashtable_t *entries;
682+
hashtable_t *entries, *ignored = NULL;
683+
backtrace_t *bt;
683684
struct {
684685
/** associated backtrace */
685686
backtrace_t *backtrace;
@@ -694,15 +695,32 @@ static int print_traces(private_leak_detective_t *this,
694695

695696
entries = hashtable_create((hashtable_hash_t)hash,
696697
(hashtable_equals_t)equals, 1024);
698+
if (whitelisted)
699+
{
700+
ignored = hashtable_create((hashtable_hash_t)hash,
701+
(hashtable_equals_t)equals, 1024);
702+
}
703+
697704
lock->lock(lock);
698705
for (hdr = first_header.next; hdr != NULL; hdr = hdr->next)
699706
{
700-
if (whitelisted &&
701-
hdr->backtrace->contains_function(hdr->backtrace,
702-
whitelist, countof(whitelist)))
707+
if (whitelisted)
703708
{
704-
(*whitelisted)++;
705-
continue;
709+
bt = ignored->get(ignored, hdr->backtrace);
710+
if (!bt)
711+
{
712+
if (hdr->backtrace->contains_function(hdr->backtrace, whitelist,
713+
countof(whitelist)))
714+
{
715+
bt = hdr->backtrace;
716+
ignored->put(ignored, bt, bt);
717+
}
718+
}
719+
if (bt)
720+
{
721+
(*whitelisted)++;
722+
continue;
723+
}
706724
}
707725
entry = entries->get(entries, hdr->backtrace);
708726
if (entry)
@@ -726,6 +744,7 @@ static int print_traces(private_leak_detective_t *this,
726744
leaks++;
727745
}
728746
lock->unlock(lock);
747+
DESTROY_IF(ignored);
729748

730749
enumerator = entries->create_enumerator(entries);
731750
while (enumerator->enumerate(enumerator, NULL, &entry))

0 commit comments

Comments
 (0)