diff --git a/src/address_cache.c b/src/address_cache.c index f8abc5df..2363ffcc 100644 --- a/src/address_cache.c +++ b/src/address_cache.c @@ -271,6 +271,8 @@ void add_recent_address(address_cache_t *cache, const sockaddr_t *sa) { } const sockaddr_t *get_recent_address(address_cache_t *cache) { + struct addrinfo *aip; + // Check if there is an address in our cache of recently seen addresses if(cache->tried < cache->data.used) { return &cache->data.address[cache->tried++]; @@ -324,11 +326,13 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) { } } - if(cache->ai) { + aip = resolve_str2addrinfo(address, port, SOCK_STREAM); + + if(aip != NULL) { free_known_addresses(cache->ai); } - cache->aip = cache->ai = resolve_str2addrinfo(address, port, SOCK_STREAM); + cache->aip = cache->ai = aip; if(cache->ai) { struct addrinfo *ai = NULL;