Fixed an obscure memory leak, potential issue with lib_runner on linux

This commit is contained in:
2023-02-04 15:30:46 +11:00
parent 2f1613e306
commit 57c16d2ede
3 changed files with 23 additions and 19 deletions

View File

@@ -224,19 +224,28 @@ static void consumeShort(Toy_Interpreter* interpreter, unsigned short bytes, uns
static bool execAssert(Toy_Interpreter* interpreter) {
Toy_Literal rhs = Toy_popLiteralArray(&interpreter->stack);
Toy_Literal lhs = Toy_popLiteralArray(&interpreter->stack);
Toy_parseIdentifierToValue(interpreter, &lhs);
Toy_Literal lhsIdn = lhs;
if (TOY_IS_IDENTIFIER(lhs) && Toy_parseIdentifierToValue(interpreter, &lhs)) {
Toy_freeLiteral(lhsIdn);
}
if (!TOY_IS_STRING(rhs)) {
interpreter->errorOutput("The assert keyword needs a string as the second argument, received: ");
Toy_printLiteralCustom(rhs, interpreter->errorOutput);
interpreter->errorOutput("\n");
Toy_freeLiteral(rhs);
Toy_freeLiteral(lhs);
return false;
}
if (TOY_IS_NULL(lhs) || !TOY_IS_TRUTHY(lhs)) {
(*interpreter->assertOutput)(Toy_toCString(TOY_AS_STRING(rhs)));
Toy_freeLiteral(rhs);
interpreter->panic = true;
Toy_freeLiteral(rhs);
Toy_freeLiteral(lhs);
return false;
}
@@ -1086,16 +1095,14 @@ static bool execFalseJump(Toy_Interpreter* interpreter) {
//actually jump
Toy_Literal lit = Toy_popLiteralArray(&interpreter->stack);
bool freeLit = false;
if (TOY_IS_IDENTIFIER(lit)) {
Toy_Literal idn = lit;
Toy_parseIdentifierToValue(interpreter, &lit);
Toy_freeLiteral(idn);
freeLit = true;
Toy_Literal litIdn = lit;
if (TOY_IS_IDENTIFIER(lit) && Toy_parseIdentifierToValue(interpreter, &lit)) {
Toy_freeLiteral(litIdn);
}
if (TOY_IS_NULL(lit)) {
interpreter->errorOutput("Null detected in comparison\n");
Toy_freeLiteral(lit);
return false;
}
@@ -1103,9 +1110,7 @@ static bool execFalseJump(Toy_Interpreter* interpreter) {
interpreter->count = target + interpreter->codeStart;
}
if (freeLit) {
Toy_freeLiteral(lit);
}
Toy_freeLiteral(lit);
return true;
}
@@ -1995,7 +2000,6 @@ static void execInterpreter(Toy_Interpreter* interpreter) {
}
break;
case TOY_OP_FN_RETURN:
if (!execFnReturn(interpreter)) {
return;

View File

@@ -23,13 +23,13 @@
//test ambiguous syntax
{
var a = 1;
var b = 2;
var c = 3;
var d = 4;
var e = 5;
var aa = 1;
var bbb = 2;
var cccc = 3;
var ddddd = 4;
var eeeeee = 5;
assert a ? b ? c : d : e == 3, "Ambiguous syntax failed";
assert aa ? bbb ? cccc : ddddd : eeeeee, "Ambiguous syntax failed";
}