X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Faddress_cache.c;h=a414f46f4c95315d5a197501689ae76674ecfc21;hb=8c8dfd6686a3d4cc11c20a09c8dfbc8321b07cdb;hp=389615ea68bd3891c2939b89714cfe615a02eef3;hpb=63fbaf7b4a33d5657cd3338b7ea91a173b9973fb;p=tinc diff --git a/src/address_cache.c b/src/address_cache.c index 389615ea..a414f46f 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); } } @@ -108,7 +109,6 @@ void add_recent_address(address_cache_t *cache, const sockaddr_t *sa) { FILE *fp = fopen(fname, "wb"); if(fp) { - fprintf(stderr, "Writing cache to %s\n", fname); fwrite(&cache->data, sizeof(cache->data), 1, fp); fclose(fp); } @@ -147,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); @@ -168,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) {