BUG/MEDIUM: dns: Release answer items when a DNS resolution is freed
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 22 Jul 2020 13:55:49 +0000 (15:55 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 23 Jul 2020 14:18:15 +0000 (16:18 +0200)
When a DNS resolution is freed, the remaining items in .ar_list and .answer_list
are also released. It must be done to avoid a memory leak. And it is the last
chance to release these objects. I've honestly no idea if there is a better
place to release them earlier. But at least, there is no more leak.

This patch should solve the issue #222. It must be backported, at least, as far
as 2.0, and probably, with caution, as far as 1.8 or 1.7.

(cherry picked from commit 010ab35a9118daf17a670fb2b42e40447f967f7c)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit c58ac80d00284886b108b209a5bf993de5ab38ed)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/dns.c

index ae8c2ce..52e7c8f 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -1339,6 +1339,7 @@ static struct dns_resolution *dns_pick_resolution(struct dns_resolvers *resolver
 static void dns_free_resolution(struct dns_resolution *resolution)
 {
        struct dns_requester *req, *reqback;
+       struct dns_answer_item *item, *itemback;
 
        /* clean up configuration */
        dns_reset_resolution(resolution);
@@ -1350,6 +1351,11 @@ static void dns_free_resolution(struct dns_resolution *resolution)
                req->resolution = NULL;
        }
 
+       list_for_each_entry_safe(item, itemback, &resolution->response.answer_list, list) {
+               LIST_DEL(&item->list);
+               pool_free(dns_answer_item_pool, item);
+       }
+
        LIST_DEL(&resolution->list);
        pool_free(dns_resolution_pool, resolution);
 }