*/
static void cache_enforce_validity(struct cache_entry *entry)
{
- time_t current_time = time(0);
+ time_t current_time = time(NULL);
if (cache_check_is_valid(entry->ipv4, current_time) == FALSE
&& entry->ipv4) {
static uint16_t cache_check_validity(char *question, uint16_t type,
struct cache_entry *entry)
{
- time_t current_time = time(0);
+ time_t current_time = time(NULL);
int want_refresh = 0;
/*
struct cache_timeout data;
int count = 0;
- data.current_time = time(0);
+ data.current_time = time(NULL);
data.max_timeout = 0;
data.try_harder = 0;
*/
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)
static void cache_refresh(void)
{
+ if (cache == NULL)
+ return;
+
g_hash_table_foreach(cache, cache_refresh_iterator, NULL);
}
return 0;
}
- current_time = time(0);
+ current_time = time(NULL);
/* don't do a cache refresh more than twice a minute */
if (next_refresh < current_time) {
data = entry->ipv6;
if (data) {
- ttl_left = data->valid_until - time(0);
+ ttl_left = data->valid_until - time(NULL);
entry->hits++;
}
}
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);
}
return 0;
}
+static void destroy_request_data(struct request_data *req)
+{
+ if (req->timeout > 0)
+ g_source_remove(req->timeout);
+
+ g_free(req->resp);
+ g_free(req->request);
+ g_free(req->name);
+ g_free(req);
+}
+
static void destroy_listener(struct listener_data *ifdata)
{
GSList *list;
DBG("Dropping pending request (id 0x%04x -> 0x%04x)",
req->srcid, req->dstid);
-
- g_free(req->resp);
- g_free(req->request);
- g_free(req->name);
- g_free(req);
+ destroy_request_data(req);
list->data = NULL;
}
DBG("Dropping request (id 0x%04x -> 0x%04x)",
req->srcid, req->dstid);
-
- g_free(req->resp);
- g_free(req->request);
- g_free(req->name);
- g_free(req);
+ destroy_request_data(req);
list->data = NULL;
}