| 1 |
From c0afec5b46eb3508fd3b1449e37b7e550f7d35e2 Mon Sep 17 00:00:00 2001
|
| 2 |
From: Gergely Nagy <algernon@balabit.hu>
|
| 3 |
Date: Fri, 08 Jun 2012 15:28:33 +0200
|
| 4 |
Subject: dnscache: Fix a memory corruption when destroying the DNS cache
|
| 5 |
|
| 6 |
The DNS cache gets destroyed every time a worker thread quits, which
|
| 7 |
is fine, as most of the dns cache variables are thread local.
|
| 8 |
|
| 9 |
However, dns_cache_hosts is not, it's a global static, and
|
| 10 |
dns_cache_destroy() was freeing that aswell.
|
| 11 |
|
| 12 |
The solution is to not free dns_cache_hosts when a worker stops, but
|
| 13 |
do so when syslog-ng stops. This patch introduces dns_cache_deinit()
|
| 14 |
which does just that, and removes the same thing from
|
| 15 |
dns_cache_destroy(), which now only touches thread-local variables.
|
| 16 |
|
| 17 |
Reported-by: EgonB <egon@local.ee>
|
| 18 |
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
|
| 19 |
---
|
| 20 |
diff --git a/lib/dnscache.c b/lib/dnscache.c
|
| 21 |
index 49102b7..9cdc2c0 100644
|
| 22 |
--- a/lib/dnscache.c
|
| 23 |
+++ b/lib/dnscache.c
|
| 24 |
@@ -361,6 +361,12 @@ dns_cache_destroy(void)
|
| 25 |
cache_last.prev = NULL;
|
| 26 |
persist_first.next = NULL;
|
| 27 |
persist_last.prev = NULL;
|
| 28 |
+}
|
| 29 |
+
|
| 30 |
+void
|
| 31 |
+dns_cache_deinit(void)
|
| 32 |
+{
|
| 33 |
if (dns_cache_hosts)
|
| 34 |
g_free(dns_cache_hosts);
|
| 35 |
+ dns_cache_hosts = NULL;
|
| 36 |
}
|
| 37 |
diff --git a/lib/dnscache.h b/lib/dnscache.h
|
| 38 |
index 8bae5f1..647ba19 100644
|
| 39 |
--- a/lib/dnscache.h
|
| 40 |
+++ b/lib/dnscache.h
|
| 41 |
@@ -34,5 +34,6 @@ void dns_cache_store(gboolean persistent, gint family, void *addr, const gchar *
|
| 42 |
void dns_cache_set_params(gint cache_size, gint expire, gint expire_failed, const gchar *hosts);
|
| 43 |
void dns_cache_init(void);
|
| 44 |
void dns_cache_destroy(void);
|
| 45 |
+void dns_cache_deinit(void);
|
| 46 |
|
| 47 |
#endif
|
| 48 |
diff --git a/lib/mainloop.c b/lib/mainloop.c
|
| 49 |
index 1203098..e294fa3 100644
|
| 50 |
--- a/lib/mainloop.c
|
| 51 |
+++ b/lib/mainloop.c
|
| 52 |
@@ -585,6 +585,7 @@ main_loop_exit_finish(void)
|
| 53 |
/* deinit the current configuration, as at this point we _know_ that no
|
| 54 |
* threads are running. This will unregister ivykis tasks and timers
|
| 55 |
* that could fire while the configuration is being destructed */
|
| 56 |
+ dns_cache_deinit();
|
| 57 |
cfg_deinit(current_configuration);
|
| 58 |
iv_quit();
|
| 59 |
}
|
| 60 |
--
|
| 61 |
cgit v0.8.3.4-1-gaabc
|