mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Scope: pop_scope() returns IntrusivePtr<>
Make sure unused scopes are freed to fix memory leaks. The comment inside pop_scope() is now obsolete and I deleted it, because this commit implements the real solution. Note that this requires us to add a reference to the push_existing_scope() call in dbg_eval_expr(), because it never owned the reference.
This commit is contained in:
parent
8ea1d89529
commit
875bfc09a2
5 changed files with 13 additions and 9 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "Scope.h"
|
||||
#include "Desc.h"
|
||||
#include "ID.h"
|
||||
#include "IntrusivePtr.h"
|
||||
#include "Val.h"
|
||||
#include "Reporter.h"
|
||||
#include "module_util.h"
|
||||
|
@ -204,21 +205,17 @@ void push_scope(ID* id, attr_list* attrs)
|
|||
scopes.push_back(top_scope);
|
||||
}
|
||||
|
||||
Scope* pop_scope()
|
||||
IntrusivePtr<Scope> pop_scope()
|
||||
{
|
||||
if ( scopes.empty() )
|
||||
reporter->InternalError("scope underflow");
|
||||
scopes.pop_back();
|
||||
|
||||
Scope* old_top = top_scope;
|
||||
// Don't delete the scope; keep it around for later name resolution
|
||||
// in the debugger.
|
||||
// ### SERIOUS MEMORY LEAK!?
|
||||
// delete top_scope;
|
||||
|
||||
top_scope = scopes.empty() ? nullptr : scopes.back();
|
||||
|
||||
return old_top;
|
||||
return {AdoptRef{}, old_top};
|
||||
}
|
||||
|
||||
Scope* current_scope()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue