mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Caught some loose memory
This commit is contained in:
@@ -53,10 +53,10 @@ print [:];
|
||||
print [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
|
||||
|
||||
//not ready yet
|
||||
//var x = 31;
|
||||
//var y : int = 42;
|
||||
//var arr : [int] = [1, 2, 3, 42];
|
||||
//var dict : [string, int] = ["hello": 1, "world":2];
|
||||
var x = 31;
|
||||
var y : int = 42;
|
||||
var arr : [int] = [1, 2, 3, 42];
|
||||
var dict : [string, int] = ["hello": 1, "world":2];
|
||||
|
||||
//print x;
|
||||
//print x + y;
|
||||
|
||||
@@ -456,6 +456,7 @@ unsigned char* collateCompiler(Compiler* compiler, int* size) {
|
||||
}
|
||||
|
||||
freeLiteralArray(ptr);
|
||||
FREE(LiteralArray, ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -486,6 +487,7 @@ unsigned char* collateCompiler(Compiler* compiler, int* size) {
|
||||
}
|
||||
|
||||
freeLiteralArray(ptr);
|
||||
FREE(LiteralArray, ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -33,8 +33,26 @@ void initInterpreter(Interpreter* interpreter, unsigned char* bytecode, int leng
|
||||
|
||||
void freeInterpreter(Interpreter* interpreter) {
|
||||
FREE_ARRAY(char, interpreter->bytecode, interpreter->length);
|
||||
|
||||
//since these are dynamically allocated, free them manually
|
||||
for (int i = 0; i < interpreter->literalCache.count; i++) {
|
||||
if (IS_ARRAY(interpreter->literalCache.literals[i]) || IS_DICTIONARY(interpreter->literalCache.literals[i]) || IS_TYPE(interpreter->literalCache.literals[i])) {
|
||||
|
||||
if (IS_TYPE(interpreter->literalCache.literals[i]) && AS_TYPE(interpreter->literalCache.literals[i]).capacity > 0) {
|
||||
FREE_ARRAY(Literal, AS_TYPE(interpreter->literalCache.literals[i]).subtypes, AS_TYPE(interpreter->literalCache.literals[i]).capacity);
|
||||
}
|
||||
|
||||
freeLiteral(interpreter->literalCache.literals[i]);
|
||||
|
||||
interpreter->literalCache.literals[i] = TO_NULL_LITERAL;
|
||||
}
|
||||
}
|
||||
freeLiteralArray(&interpreter->literalCache);
|
||||
|
||||
while (interpreter->scope) {
|
||||
interpreter->scope = popScope(interpreter->scope);
|
||||
}
|
||||
|
||||
freeLiteralArray(&interpreter->stack);
|
||||
}
|
||||
|
||||
|
||||
@@ -344,7 +344,6 @@ void freeLiteral(Literal literal) {
|
||||
for (int i = 0; i < AS_TYPE(literal).count; i++) {
|
||||
freeLiteral(((Literal*)(AS_TYPE(literal).subtypes))[i]);
|
||||
}
|
||||
FREE_ARRAY(Literal, AS_TYPE(literal).subtypes, AS_TYPE(literal).capacity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user