Reduce pointer indirection for global list_t variables
[tinc] / src / address_cache.c
index 389615e..df465da 100644 (file)
@@ -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);
        }
@@ -152,7 +152,7 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) {
                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) {