diff --git a/src/engine/compile.cpp b/src/engine/compile.cpp index 75299bc9d..daeb3d2f9 100644 --- a/src/engine/compile.cpp +++ b/src/engine/compile.cpp @@ -145,10 +145,8 @@ LIST * evaluate_rule( RULE * rule, OBJECT * rulename, FRAME * frame ) */ if ( rule->procedure ) { - FUNCTION * const function = rule->procedure; - function_refer( function ); - result = function_run( function, frame, stack_global() ); - function_free( function ); + auto function = b2::jam::make_unique_bare_jptr( rule->procedure, function_refer, function_free ); + result = function_run( function.get(), frame, stack_global() ); } if ( DEBUG_PROFILE && rule->procedure ) diff --git a/src/engine/parse.cpp b/src/engine/parse.cpp index 1eb48fdb8..d1588ab75 100644 --- a/src/engine/parse.cpp +++ b/src/engine/parse.cpp @@ -18,6 +18,7 @@ #include "modules.h" #include "frames.h" #include "function.h" +#include "mem.h" /* * parse.c - make and destroy parse trees as driven by the parser @@ -40,7 +41,6 @@ static void parse_impl( FRAME * frame ) for ( ; ; ) { PARSE * p; - FUNCTION * func; /* Filled by yyparse() calling parse_save(). */ yypsave = 0; @@ -50,10 +50,9 @@ static void parse_impl( FRAME * frame ) break; /* Run the parse tree. */ - func = function_compile( p ); + auto func = b2::jam::make_unique_bare_jptr( function_compile( p ), function_free ); parse_free( p ); - list_free( function_run( func, frame, stack_global() ) ); - function_free( func ); + list_free( function_run( func.get(), frame, stack_global() ) ); } yyfdone();