zeek/testing/btest/core/leaks/input-optional-event.bro
Bernhard Amann 504d22b91b fix memory leak in input framework.
If the input framework was used to read event streams and
those streams contained records with more than one field, not all
elements of the threading Values were cleaned up.

The reason for this is, that the SendEventStreamEvent function
returned the number of record elements in the outmost record
instead of the number of unrolled elements in the whole vector.

This number is later used to determine how many objects to delete.

Also - add a whole bunch of leak checks for the input framework
that would have caught that and should cover quite a number of
use-cases.
2013-12-05 10:53:12 -08:00

65 lines
1.1 KiB
Text

# 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 -m -b %INPUT
# @TEST-EXEC: btest-bg-wait 15
@TEST-START-FILE input.log
#separator \x09
#path ssh
#fields i b r.a r.b r.c
#types int bool string string string
1 T a b c
2 T a b c
3 F ba bb bc
4 T bb bd -
5 F a b c
6 T a b c
7 T a b c
@TEST-END-FILE
redef exit_only_after_terminate = T;
global outfile: file;
redef InputAscii::empty_field = "EMPTY";
module A;
type Sub: record {
a: string;
aa: string &optional;
b : string;
bb: string &optional;
c: string &optional;
d: string &optional;
};
type Val: record {
i: int;
b: bool;
notb: bool &optional;
r: Sub;
};
event servers(desc: Input::EventDescription, tpe: Input::Event, item: Val)
{
print outfile, item;
}
event bro_init()
{
outfile = open("../out");
# first read in the old stuff into the table...
Input::add_event([$source="../input.log", $name="input", $fields=Val, $ev=servers]);
}
event Input::end_of_data(name: string, source: string)
{
Input::remove("input");
close(outfile);
terminate();
}