From 96dfc7b6e1baa28dee6f6b9c16546b9d61264d1d Mon Sep 17 00:00:00 2001 From: Mathew Date: Sat, 10 Jun 2023 17:07:24 +1000 Subject: [PATCH] Update address_cache.c --- src/address_cache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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;