Fix memory leak for compiler constants

The ownership for constants is not transfered to the new function so the
constant buffer must be cleared when the compiler is finished.
This commit is contained in:
André Althaus
2015-06-03 21:47:16 +02:00
parent 0add2195f3
commit 33151c64d2

View File

@ -1280,6 +1280,7 @@ static void freeCompiler(Compiler* compiler)
{
wrenByteBufferClear(compiler->parser->vm, &compiler->bytecode);
wrenIntBufferClear(compiler->parser->vm, &compiler->debugSourceLines);
wrenValueBufferClear(compiler->parser->vm, &compiler->constants);
}
// Finishes [compiler], which is compiling a function, method, or chunk of top
@ -1317,6 +1318,9 @@ static ObjFn* endCompiler(Compiler* compiler,
compiler->debugSourceLines.data);
wrenPushRoot(compiler->parser->vm, (Obj*)fn);
// Clear constants. The constants are copied by wrenNewFunction
wrenValueBufferClear(compiler->parser->vm, &compiler->constants);
// In the function that contains this one, load the resulting function object.
if (compiler->parent != NULL)
{