Merge branch 'leaks' of https://github.com/NomAnor/wren into NomAnor-leaks

This commit is contained in:
Bob Nystrom
2015-06-26 22:49:24 -07:00
4 changed files with 26 additions and 1 deletions
+4
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)
{
+17 -1
View File
@@ -22,9 +22,25 @@
#include <time.h>
#endif
static void* defaultReallocate(void* ptr, size_t new_size)
{
// The behavior of realloc for size == 0 is implementation defined.
// It can return a non NULL pointer which must not be dereferenced but nether
// the less must be freed. When calling the wren reallocation function with
// size == 0 the memory pointed to ptr must be freed and NULL returned.
if (ptr == NULL && new_size == 0) return NULL;
if (ptr != NULL && new_size == 0)
{
free(ptr);
return NULL;
}
return realloc(ptr, new_size);
}
WrenVM* wrenNewVM(WrenConfiguration* configuration)
{
WrenReallocateFn reallocate = realloc;
WrenReallocateFn reallocate = defaultReallocate;
if (configuration->reallocateFn != NULL)
{
reallocate = configuration->reallocateFn;