diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2012-01-20 09:53:58 +0200 |
---|---|---|
committer | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2012-01-24 11:41:43 +0100 |
commit | fd06d528d213ef40c9f9fac80b7c6f840a852034 (patch) | |
tree | 7ca0272348f8d4046754ca9a4b1235f74dba1b07 /src/dnsproxy.c | |
parent | 862a3c893b7ffabb22e6efcad50282013edea59f (diff) | |
download | connman-fd06d528d213ef40c9f9fac80b7c6f840a852034.tar.gz connman-fd06d528d213ef40c9f9fac80b7c6f840a852034.tar.bz2 connman-fd06d528d213ef40c9f9fac80b7c6f840a852034.zip |
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.
Diffstat (limited to 'src/dnsproxy.c')
-rw-r--r-- | src/dnsproxy.c | 16 |
1 files changed, 12 insertions, 4 deletions
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); } |