Fix another leak
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 15s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 12s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 10s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 10s

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-07-27 23:16:47 +03:00
parent dbaf6d16ce
commit a8ea92dd5c
2 changed files with 45 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
{
test = 123;
test.field = 456; # This should be invalid. `test` is an int, not an object.
test = 123
test.field = 456 # This should be invalid. `test` is an int, not an object.
}

View File

@@ -429,11 +429,35 @@ static void skip_ws_and_comments(Lexer *lx)
for (;;) {
while (is_space(lx->ch))
lex_advance(lx);
if (lx->ch == '#') {
while (lx->ch != -1 && lx->ch != '\n')
lex_advance(lx);
continue;
}
if (lx->ch == '/' && lx->next == '/') {
lex_advance(lx);
lex_advance(lx);
while (lx->ch != -1 && lx->ch != '\n')
lex_advance(lx);
continue;
}
if (lx->ch == '/' && lx->next == '*') {
lex_advance(lx);
lex_advance(lx);
while (lx->ch != -1) {
if (lx->ch == '*' && lx->next == '/') {
lex_advance(lx);
lex_advance(lx); /* / */
break;
}
lex_advance(lx);
}
continue;
}
break;
}
}
@@ -1082,7 +1106,11 @@ Value *ast_to_value(dcfg_Instance *instance, AST *root)
ASTBlock_Entry *e = &root->v.bl.entryv[i];
Value *rhs = ast_to_value(instance, e->v);
if (!rhs) {
// FIXME: Free
for (size_t j = 0; j < vector_size(value->v.o.entryv); j++) {
dcfg_destroy(value->v.o.entryv[j].v);
}
vector_free(value->v.o.entryv);
FREE(value);
return NULL;
}
@@ -1098,6 +1126,17 @@ Value *ast_to_value(dcfg_Instance *instance, AST *root)
field = ma->accessv[vector_size(ma->accessv) - 1];
}
if (target->type != dcfg_ValueType_Object) {
strcpy(instance->last_error,
"Previous declaration is not an object");
dcfg_destroy(rhs);
for (size_t j = 0; j < vector_size(value->v.o.entryv); j++)
dcfg_destroy(value->v.o.entryv[j].v);
vector_free(value->v.o.entryv);
FREE(value);
return NULL;
}
ValueObject *obj = &target->v.o;
bool replaced = false;
for (size_t j = 0; j < vector_size(obj->entryv); ++j) {
@@ -1160,11 +1199,10 @@ Value *ast_to_value(dcfg_Instance *instance, AST *root)
for (size_t i = 0; i < vector_size(root->v.fc.argv); i++) {
Value *arg = ast_to_value(instance, root->v.fc.argv[i]);
if (!arg) {
// TODO: Free argv values
for (size_t i = 0; i < vector_size(value->v.c.argv); i++) {
for (size_t i = 0; i < vector_size(value->v.c.argv); i++)
dcfg_destroy(value->v.c.argv[i]);
}
vector_free(value->v.c.argv);
dcfg_destroy(value->v.c.function);
FREE(value);
return NULL;
}
@@ -1262,6 +1300,7 @@ dcfg_Value *dcfg_parse(dcfg_Instance *instance, dcfg_StringView const file_path)
instance->last_error[0] = '\0';
Value *v = ast_to_value(instance, ast);
AST_free_parser(ast, &parser);
if (!v) {
if (!*instance->last_error) {
strcpy(instance->last_error, "Could not get Value tree from AST");
@@ -1274,8 +1313,6 @@ dcfg_Value *dcfg_parse(dcfg_Instance *instance, dcfg_StringView const file_path)
}
instance->last_error[0] = '\0';
AST_free_parser(ast, &parser);
vector_add(&instance->sourcev, str);
v->i_sourcev_idx = vector_size(instance->sourcev) - 1;