From b0fa80e34881152350d3994eb1d28687d4d47d84 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Fri, 20 Sep 2019 19:21:33 -0400 Subject: Fix double free of array info --- tree.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tree.c b/tree.c index d218eed..d59fd18 100644 --- a/tree.c +++ b/tree.c @@ -64,7 +64,8 @@ void update_type_info(list, t) ptree *list, *t; { int type; - struct ai *info = NULL; + struct ai *info, *tmp; + info = tmp = NULL; assert(list && t); type = t->type; @@ -82,9 +83,14 @@ ptree *list, *t; } else while (list->r && list->r->type == ID) { /*Set type of right child through list*/ list->r->attr.nval->var_type = type; - if (info) + if (info){ list->r->attr.nval->array_info = info; + assert(tmp = malloc(sizeof(struct ai))); + memcpy(tmp, info, sizeof(struct ai)); + info = tmp; + } + if (list->l) { if (list->l->type == LIST) { list = list->l; @@ -95,6 +101,10 @@ ptree *list, *t; list->l->attr.nval->var_type = type; if (info){ list->l->attr.nval->array_info = info; + + assert(tmp = malloc(sizeof(struct ai))); + memcpy(tmp, info, sizeof(struct ai)); + info = tmp; } } } -- cgit v1.1