Fix memory leak in DNS TXT lookups.

This commit is contained in:
Jon Siwek 2013-09-04 16:47:44 -05:00
parent 6ad82ff263
commit 62de5678f7
2 changed files with 54 additions and 1 deletions

View file

@ -713,6 +713,16 @@ void DNS_Mgr::AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r)
TextMap::iterator it = text_mappings.find(dr->ReqHost()); TextMap::iterator it = text_mappings.find(dr->ReqHost());
if ( it == text_mappings.end() ) if ( it == text_mappings.end() )
text_mappings[dr->ReqHost()] = new_dm; text_mappings[dr->ReqHost()] = new_dm;
else
{
if ( new_dm->Failed() && prev_dm && prev_dm->Valid() )
++keep_prev;
else
{
prev_dm = it->second;
it->second = new_dm;
}
}
} }
else else
{ {
@ -766,7 +776,7 @@ void DNS_Mgr::AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r)
} }
} }
if ( prev_dm ) if ( prev_dm && ! dr->ReqIsTxt() )
CompareMappings(prev_dm, new_dm); CompareMappings(prev_dm, new_dm);
if ( keep_prev ) if ( keep_prev )

View file

@ -0,0 +1,43 @@
# Needs perftools support.
#
# @TEST-GROUP: leaks
#
# @TEST-REQUIRES: bro --help 2>&1 | grep -q mem-leaks
#
# @TEST-EXEC: HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local btest-bg-run bro bro -b -m -r $TRACES/wikipedia.trace %INPUT
# @TEST-EXEC: btest-bg-wait 15
@load base/frameworks/communication # keep network time running
redef exit_only_after_terminate = T;
global n1 = 0;
function check_term_conditions()
{
if ( n1 > 7 )
terminate();
}
event do_txt(s: string)
{
when ( local t1 = lookup_hostname_txt(s) )
{
print "t1", t1;
++n1;
check_term_conditions();
}
timeout 100secs
{
print "t1 timeout";
++n1;
check_term_conditions();
}
}
event connection_established(c: connection)
{
event do_txt("localhost");
schedule 5sec { do_txt("localhost") };
}