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:
Max Kellermann 2020-02-26 05:48:38 +01:00
parent 8ea1d89529
commit 875bfc09a2
5 changed files with 13 additions and 9 deletions

View file

@ -8,6 +8,7 @@
#include "Val.h"
#include "Expr.h"
#include "Func.h"
#include "IntrusivePtr.h"
#include "Stmt.h"
#include "Scope.h"
#include "Reporter.h"
@ -468,7 +469,7 @@ TraversalCode OuterIDBindingFinder::PostExpr(const Expr* expr)
void end_func(IntrusivePtr<Stmt> body)
{
auto ingredients = std::make_unique<function_ingredients>(pop_scope(), body.release());
auto ingredients = std::make_unique<function_ingredients>(pop_scope().release(), body.release());
if ( streq(ingredients->id->Name(), "anonymous-function") )
{