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
14
src/Stmt.cc
14
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();
|
IterCookie* c = loop_vals->InitForIteration();
|
||||||
while ( (current_tev = loop_vals->NextEntry(k, c)) )
|
while ( (current_tev = loop_vals->NextEntry(k, c)) )
|
||||||
{
|
{
|
||||||
ListVal* ind_lv = tv->RecoverIndex(k);
|
IntrusivePtr<ListVal> ind_lv{AdoptRef{}, tv->RecoverIndex(k)};
|
||||||
delete k;
|
delete k;
|
||||||
|
|
||||||
if ( value_var )
|
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++ )
|
for ( int i = 0; i < ind_lv->Length(); i++ )
|
||||||
f->SetElement((*loop_vars)[i], ind_lv->Index(i)->Ref());
|
f->SetElement((*loop_vars)[i], ind_lv->Index(i)->Ref());
|
||||||
Unref(ind_lv);
|
|
||||||
|
|
||||||
flow = FLOW_NEXT;
|
flow = FLOW_NEXT;
|
||||||
ret = body->Exec(f, flow);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = body->Exec(f, flow);
|
||||||
|
}
|
||||||
|
catch ( InterpreterException& )
|
||||||
|
{
|
||||||
|
loop_vals->StopIteration(c);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
if ( flow == FLOW_BREAK || flow == FLOW_RETURN )
|
if ( flow == FLOW_BREAK || flow == FLOW_RETURN )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue