From 5a66104adbdb9e6a3396b1d2539b7b7b56bf1ec6 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 27 Jun 2007 11:12:58 +0000 Subject: [PATCH] fixup memory leak. git-svn-id: file:///svn/unbound/trunk@426 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 2 ++ iterator/iter_utils.c | 6 +++++- services/cache/dns.c | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 2f7ff4c8a..f14af3928 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,7 @@ 27 June 2007: Wouter - delete of mesh does a postorder traverse of the tree. + - found and fixed a memory leak. For TTL=0 messages, that would + not be cached, instead the msg-replyinfo structure was leaked. 26 June 2007: Wouter - mesh is called by worker, and iterator uses it. diff --git a/iterator/iter_utils.c b/iterator/iter_utils.c index d728cf031..df3decd79 100644 --- a/iterator/iter_utils.c +++ b/iterator/iter_utils.c @@ -317,8 +317,10 @@ iter_dns_store(struct module_env* env, struct dns_msg* msg, int is_referral) qinf = msg->qinfo; qinf.qname = memdup(msg->qinfo.qname, msg->qinfo.qname_len); - if(!qinf.qname) + if(!qinf.qname) { + reply_info_parsedelete(msg->rep, env->alloc); return 0; + } /* fixup flags to be sensible for a reply based on the cache */ /* this module means that RA is available. It is an answer QR. * Not AA from cache. Not CD in cache (depends on client bit). */ @@ -326,6 +328,8 @@ iter_dns_store(struct module_env* env, struct dns_msg* msg, int is_referral) rep->flags &= ~(BIT_AA | BIT_CD); h = query_info_hash(&qinf); dns_cache_store_msg(env, &qinf, h, rep); + /* qname is used inside query_info_entrysetup, and set to + * NULL. If it has not been used, free it. free(0) is safe. */ free(qinf.qname); } return 1; diff --git a/services/cache/dns.c b/services/cache/dns.c index 14cd72263..f6045fe17 100644 --- a/services/cache/dns.c +++ b/services/cache/dns.c @@ -78,8 +78,8 @@ dns_cache_store_msg(struct module_env* env, struct query_info* qinfo, /* store RRsets */ for(i=0; irrset_count; i++) { - rep->ref[i].key = rep->rrsets[i]; - rep->ref[i].id = rep->rrsets[i]->id; + rep->ref[i].key = rep->rrsets[i]; + rep->ref[i].id = rep->rrsets[i]->id; } reply_info_sortref(rep); reply_info_set_ttls(rep, now); @@ -88,6 +88,7 @@ dns_cache_store_msg(struct module_env* env, struct query_info* qinfo, /* we do not store the message, but we did store the RRs, * which could be useful for delegation information */ verbose(VERB_ALGO, "TTL 0: dropped msg from cache"); + free(rep); return; } -- 2.47.2