From fd06d528d213ef40c9f9fac80b7c6f840a852034 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 20 Jan 2012 09:53:58 +0200 Subject: dnsproxy: Check that cache is valid before accessing it. The cache can become invalid by just disconnecting a service. In that case we must not access the cache hash. --- src/dnsproxy.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/dnsproxy.c') diff --git a/src/dnsproxy.c b/src/dnsproxy.c index 6f8d39a4..dc44a46d 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -1130,9 +1130,12 @@ static gboolean cache_invalidate_entry(gpointer key, gpointer value, */ static void cache_invalidate(void) { - DBG("Invalidating the DNS cache"); - g_hash_table_foreach_remove(cache, cache_invalidate_entry, - NULL); + DBG("Invalidating the DNS cache %p", cache); + + if (cache == NULL) + return; + + g_hash_table_foreach_remove(cache, cache_invalidate_entry, NULL); } static void cache_refresh_entry(struct cache_entry *entry) @@ -1175,6 +1178,9 @@ static void cache_refresh_iterator(gpointer key, gpointer value, static void cache_refresh(void) { + if (cache == NULL) + return; + g_hash_table_foreach(cache, cache_refresh_iterator, NULL); } @@ -1650,8 +1656,10 @@ static void destroy_server(struct server_data *server) } g_free(server->interface); - if (__sync_fetch_and_sub(&cache_refcount, 1) == 1) + if (__sync_fetch_and_sub(&cache_refcount, 1) == 1) { g_hash_table_destroy(cache); + cache = NULL; + } g_free(server); } -- cgit v1.2.3