X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Faddress_cache.c;h=d9996fb0b53f6fc354a8899b305a442c96ce1172;hb=d93d4f9dbd09bc5e53a9b5eeb1cc94939fee32bc;hp=445cd1c522804bb29cd21633acda2cbfb28435da;hpb=291b8f864ea57dd68b894a3b1482ee822aad66ed;p=tinc diff --git a/src/address_cache.c b/src/address_cache.c index 445cd1c5..d9996fb0 100644 --- a/src/address_cache.c +++ b/src/address_cache.c @@ -32,7 +32,7 @@ static struct addrinfo *get_known_addresses(node_t *n) { struct addrinfo *ai = NULL; struct addrinfo *oai = NULL; - for splay_each(edge_t, e, n->edge_tree) { + for splay_each(edge_t, e, &n->edge_tree) { if(!e->reverse) { continue; } @@ -67,6 +67,7 @@ static struct addrinfo *get_known_addresses(node_t *n) { static void free_known_addresses(struct addrinfo *ai) { for(struct addrinfo *aip = ai, *next; aip; aip = next) { next = aip->ai_next; + free(aip->ai_addr); free(aip); } } @@ -146,12 +147,12 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) { // Otherwise, check if there are any known Address statements if(!cache->config_tree) { - init_configuration(&cache->config_tree); + cache->config_tree = create_configuration(); read_host_config(cache->config_tree, cache->node->name, false); cache->cfg = lookup_config(cache->config_tree, "Address"); } - while(cache->cfg && !cache->ai) { + while(cache->cfg && !cache->aip) { char *address, *port; get_config_string(cache->cfg, &address); @@ -167,6 +168,10 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) { } } + if(cache->ai) { + free_known_addresses(cache->ai); + } + cache->aip = cache->ai = str2addrinfo(address, port, SOCK_STREAM); if(cache->ai) { @@ -208,7 +213,9 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) { } // We're all out of addresses. - exit_configuration(&cache->config_tree); + exit_configuration(cache->config_tree); + cache->config_tree = NULL; + return false; } @@ -250,7 +257,8 @@ void reset_address_cache(address_cache_t *cache, const sockaddr_t *sa) { } if(cache->config_tree) { - exit_configuration(&cache->config_tree); + exit_configuration(cache->config_tree); + cache->config_tree = NULL; } if(cache->ai) { @@ -266,7 +274,8 @@ void reset_address_cache(address_cache_t *cache, const sockaddr_t *sa) { void close_address_cache(address_cache_t *cache) { if(cache->config_tree) { - exit_configuration(&cache->config_tree); + exit_configuration(cache->config_tree); + cache->config_tree = NULL; } if(cache->ai) {