fix: rotate_entfield_array_index_nodes deleting the old array caused expressions to be deleted recursively

This commit is contained in:
Wolfgang Bumiller 2013-02-03 23:38:06 +01:00
parent 530dbd85b2
commit e662efae61
2 changed files with 10 additions and 4 deletions

6
ast.c
View file

@ -660,8 +660,10 @@ ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_exp
void ast_array_index_delete(ast_array_index *self)
{
ast_unref(self->array);
ast_unref(self->index);
if (self->array)
ast_unref(self->array);
if (self->index)
ast_unref(self->index);
ast_expression_delete((ast_expression*)self);
mem_d(self);
}

View file

@ -449,7 +449,7 @@ static sy_elem syparen(lex_ctx ctx, size_t off) {
*/
static bool rotate_entfield_array_index_nodes(ast_expression **out)
{
ast_array_index *index;
ast_array_index *index, *oldindex;
ast_entfield *entfield;
ast_value *field;
@ -473,12 +473,16 @@ static bool rotate_entfield_array_index_nodes(ast_expression **out)
sub = index->index;
entity = entfield->entity;
ast_delete(index);
oldindex = index;
index = ast_array_index_new(ctx, (ast_expression*)field, sub);
entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
*out = (ast_expression*)entfield;
oldindex->array = NULL;
oldindex->index = NULL;
ast_delete(oldindex);
return true;
}