leak-detective: call tzset() explicitly before enabling leak detective
authorMartin Willi <martin@revosec.ch>
Tue, 2 Apr 2013 13:47:55 +0000 (15:47 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 6 May 2013 13:15:24 +0000 (15:15 +0200)
tzset() is hard to whitelist on some systems, as there is no symbol involved.
Call tzset() explicitly before initialization to avoid false positives.

src/libstrongswan/utils/leak_detective.c

index 69e539d..2883b88 100644 (file)
@@ -27,6 +27,7 @@
 #include <netdb.h>
 #include <locale.h>
 #include <dlfcn.h>
+#include <time.h>
 
 #include "leak_detective.h"
 
@@ -283,12 +284,6 @@ char *whitelist[] = {
        "pthread_setspecific",
        "__pthread_setspecific",
        /* glibc functions */
-       "mktime",
-       "ctime",
-       "__gmtime_r",
-       "localtime_r",
-       "tzset",
-       "time_printf_hook",
        "inet_ntoa",
        "strerror",
        "getprotobyname",
@@ -366,6 +361,14 @@ char *whitelist[] = {
        "gnutls_global_init",
 };
 
+/**
+ * Some functions are hard to whitelist, as they don't use a symbol directly.
+ * Use some static initialization to suppress them on leak reports
+ */
+static void init_static_allocations()
+{
+       tzset();
+}
 
 /**
  * Hashtable hash function
@@ -748,6 +751,8 @@ leak_detective_t *leak_detective_create()
        lock = spinlock_create();
        thread_disabled = thread_value_create(NULL);
 
+       init_static_allocations();
+
        if (getenv("LEAK_DETECTIVE_DISABLE") == NULL)
        {
                enable_leak_detective();