mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 03:58:20 +00:00
Fix memory leaks resulting from 'when' and 'return when' statements.
Addresses #946.
This commit is contained in:
parent
7e5115460c
commit
d158c7ffdf
6 changed files with 106 additions and 6 deletions
84
testing/btest/core/leaks/returnwhen.bro
Normal file
84
testing/btest/core/leaks/returnwhen.bro
Normal file
|
@ -0,0 +1,84 @@
|
|||
# Needs perftools support.
|
||||
#
|
||||
# @TEST-GROUP: leaks
|
||||
#
|
||||
# @TEST-REQUIRES: bro --help 2>&1 | grep -q mem-leaks
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run bro HEAP_CHECK_DUMP_DIRECTORY=. HEAPCHECK=local bro -m -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 15
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global my_set: set[string] = set();
|
||||
global flag: string = "flag";
|
||||
global done: bool = F;
|
||||
|
||||
function dummyfunc(s: string): string
|
||||
{
|
||||
return "dummy " + s;
|
||||
}
|
||||
|
||||
function async_func(s: string): string
|
||||
{
|
||||
print dummyfunc("from async_func() " + s);
|
||||
|
||||
return when ( flag in my_set )
|
||||
{
|
||||
return flag + " in my_set";
|
||||
}
|
||||
timeout 3sec
|
||||
{
|
||||
return "timeout";
|
||||
}
|
||||
}
|
||||
|
||||
event set_flag()
|
||||
{
|
||||
add my_set[flag];
|
||||
}
|
||||
|
||||
event do_another()
|
||||
{
|
||||
delete my_set[flag];
|
||||
|
||||
local local_dummy = dummyfunc;
|
||||
|
||||
local anon = function(s: string): string { return s + "!"; };
|
||||
|
||||
if ( ! done )
|
||||
schedule 1sec { set_flag() };
|
||||
|
||||
when ( local result = async_func("from do_another()") )
|
||||
{
|
||||
print "async_func() return result in do_another()", result;
|
||||
print local_dummy("from do_another() when block");
|
||||
print anon("hi");
|
||||
if ( result == "timeout" )
|
||||
terminate();
|
||||
else
|
||||
{
|
||||
done = T;
|
||||
schedule 10msec { do_another() };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local local_dummy = dummyfunc;
|
||||
|
||||
local anon = function(s: string): string { return s + "!"; };
|
||||
|
||||
schedule 1sec { set_flag() };
|
||||
|
||||
when ( local result = async_func("from bro_init()") )
|
||||
{
|
||||
print "async_func() return result in bro_init()", result;
|
||||
print local_dummy("from bro_init() when block");
|
||||
print anon("hi");
|
||||
if ( result == "timeout" ) terminate();
|
||||
schedule 10msec { do_another() };
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue