Skip to content

Commit

Permalink
Fix memory leak in compiler
Browse files Browse the repository at this point in the history
Reference count is properly handled by string table and usage of
SQObject is ok here, but if we use SQObjectPtr local variable and
compiler error occurs, its destructor is not called because of longjmp.
That leads to incorrectly incremented refcount and memory leak.
  • Loading branch information
VasiliyRyabtsev committed Nov 23, 2021
1 parent 232e1f2 commit 1fa5f6b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions squirrel/sqcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ class SQCompiler
}
}

SQObjectPtr generateSurrogateFunctionName()
SQObject generateSurrogateFunctionName()
{
const SQChar * fileName = (sq_type(_sourcename) == OT_STRING) ? _stringval(_sourcename) : _SC("unknown");
int lineNum = int(_lex._currentline);
Expand All @@ -1884,7 +1884,7 @@ class SQCompiler
void FunctionExp(SQInteger ftype,bool lambda = false)
{
Lex();
SQObjectPtr functionName = (_token == TK_IDENTIFIER) ? Expect(TK_IDENTIFIER) : generateSurrogateFunctionName();
SQObject functionName = (_token == TK_IDENTIFIER) ? Expect(TK_IDENTIFIER) : generateSurrogateFunctionName();
Expect(_SC('('));

CreateFunction(functionName, lambda);
Expand Down

0 comments on commit 1fa5f6b

Please sign in to comment.