mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Fix memory leak when runtime error occurs in a Zeek for-loop
This commit is contained in:
parent
98d94ec785
commit
7a4ce9fb51
1 changed files with 11 additions and 3 deletions
12
src/Stmt.cc
12
src/Stmt.cc
|
@ -1198,7 +1198,7 @@ IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
|
|||
IterCookie* c = loop_vals->InitForIteration();
|
||||
while ( (current_tev = loop_vals->NextEntry(k, c)) )
|
||||
{
|
||||
ListVal* ind_lv = tv->RecoverIndex(k);
|
||||
IntrusivePtr<ListVal> ind_lv{AdoptRef{}, tv->RecoverIndex(k)};
|
||||
delete k;
|
||||
|
||||
if ( value_var )
|
||||
|
@ -1206,10 +1206,18 @@ IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
|
|||
|
||||
for ( int i = 0; i < ind_lv->Length(); i++ )
|
||||
f->SetElement((*loop_vars)[i], ind_lv->Index(i)->Ref());
|
||||
Unref(ind_lv);
|
||||
|
||||
flow = FLOW_NEXT;
|
||||
|
||||
try
|
||||
{
|
||||
ret = body->Exec(f, flow);
|
||||
}
|
||||
catch ( InterpreterException& )
|
||||
{
|
||||
loop_vals->StopIteration(c);
|
||||
throw;
|
||||
}
|
||||
|
||||
if ( flow == FLOW_BREAK || flow == FLOW_RETURN )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue