Merge remote-tracking branch 'origin/topic/johanna/stats_smb_leak'

BIT-1534 #merged

* origin/topic/johanna/stats_smb_leak:
  Fix memory leaks in stats.cc and smb.cc
This commit is contained in:
Robin Sommer 2016-02-13 10:40:16 -08:00
commit 124531d4ae
6 changed files with 34 additions and 8 deletions

View file

@ -1,4 +1,8 @@
2.4-280 | 2016-02-13 10:40:16 -0800
* Fix memory leaks in stats.cc and smb.cc. (Johanna Amann)
2.4-278 | 2016-02-12 18:53:35 -0800
* Better multi-space separator handline. (Mark Taylor & Johanna Amann)

View file

@ -1 +1 @@
2.4-278
2.4-280

View file

@ -362,12 +362,16 @@ SampleLogger::~SampleLogger()
void SampleLogger::FunctionSeen(const Func* func)
{
load_samples->Assign(new StringVal(func->Name()), 0);
Val* idx = new StringVal(func->Name());
load_samples->Assign(idx, 0);
Unref(idx);
}
void SampleLogger::LocationSeen(const Location* loc)
{
load_samples->Assign(new StringVal(loc->filename), 0);
Val* idx = new StringVal(loc->filename);
load_samples->Assign(idx, 0);
Unref(idx);
}
void SampleLogger::SegmentProfile(const char* /* name */,

View file

@ -753,10 +753,11 @@ public:
TableVal(TableType* t, Attributes* attrs = 0);
~TableVal();
// Returns true if the assignment typechecked, false if not.
// Second version takes a HashKey and Unref()'s it when done.
// If we're a set, new_val has to be nil.
// If we aren't a set, index may be nil in the second version.
// Returns true if the assignment typechecked, false if not. The
// methods take ownership of new_val, but not of the index. Second
// version takes a HashKey and Unref()'s it when done. If we're a
// set, new_val has to be nil. If we aren't a set, index may be nil
// in the second version.
int Assign(Val* index, Val* new_val, Opcode op = OP_ASSIGN);
int Assign(Val* index, HashKey* k, Val* new_val, Opcode op = OP_ASSIGN);

View file

@ -336,7 +336,9 @@ int SMB_Session::ParseNegotiate(binpac::SMB::SMB_header const& hdr,
{
binpac::SMB::SMB_dialect* d = (*msg.dialects())[i];
BroString* tmp = ExtractString(d->dialectname());
t->Assign(new Val(i, TYPE_COUNT), new StringVal(tmp));
Val* idx = new Val(i, TYPE_COUNT);
t->Assign(idx, new StringVal(tmp));
Unref(idx);
}
val_list* vl = new val_list;

View file

@ -0,0 +1,15 @@
# 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 -r $TRACES/wikipedia.trace %INPUT
# @TEST-EXEC: btest-bg-wait 60
@load policy/misc/stats.bro
event load_sample(samples: load_sample_info, CPU: interval, dmem: int)
{
print CPU;
}