From 69c03ced046f3e2e3d77cc2caf25335087fae51f Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Thu, 31 Mar 2022 00:42:18 -0500 Subject: [PATCH] Fix memory leak for invoked function args. If a function exits abnormally, for any reason, the passed in function frame args would leak. This change captures such early exits and cleans up the args for directly invoked functions. This clears up about 70% of current memory leaks. --- src/engine/compile.cpp | 11 ++++++++++- src/engine/jam.cpp | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/engine/compile.cpp b/src/engine/compile.cpp index b16826905..3a85a03f2 100644 --- a/src/engine/compile.cpp +++ b/src/engine/compile.cpp @@ -37,6 +37,7 @@ #include "jam_strings.h" #include "variable.h" #include "output.h" +#include "startup.h" #include #include @@ -146,7 +147,15 @@ LIST * evaluate_rule( RULE * rule, OBJECT * rulename, FRAME * frame ) if ( rule->procedure ) { auto function = b2::jam::make_unique_bare_jptr( rule->procedure, function_refer, function_free ); - result = function_run( function.get(), frame ); + try + { + result = function_run( function.get(), frame ); + } + catch( b2::exit_result r ) + { + lol_free( frame->args ); + b2::clean_exit( r ); + } } if ( DEBUG_PROFILE && rule->procedure ) diff --git a/src/engine/jam.cpp b/src/engine/jam.cpp index 5c3baff7c..42a69cd1e 100644 --- a/src/engine/jam.cpp +++ b/src/engine/jam.cpp @@ -681,6 +681,8 @@ int main( int argc, char * * argv ) catch ( b2::exit_result exit_code ) { result = (int)exit_code; + out_flush(); + err_flush(); } if ( DEBUG_PROFILE )