sv: fix a few struct and enum memory leaks
authorZachary Snow <zach@zachjs.com>
Thu, 17 Jun 2021 19:59:59 +0000 (15:59 -0400)
committerZachary Snow <zachary.j.snow@gmail.com>
Tue, 6 Jul 2021 16:15:08 +0000 (12:15 -0400)
frontends/ast/simplify.cc
frontends/verilog/verilog_parser.y

index f853064234185ea2d2d11a17e1282ccd6fdf32d5..695fc429dd26917b53ba59c8902c8d1b3b66e4ed 100644 (file)
@@ -331,6 +331,8 @@ static int size_packed_struct(AstNode *snode, int base_offset)
                                        }
                                }
                                // range nodes are now redundant
+                               for (AstNode *child : node->children)
+                                       delete child;
                                node->children.clear();
                        }
                        else if (node->children.size() == 1 && node->children[0]->type == AST_MULTIRANGE) {
@@ -345,6 +347,8 @@ static int size_packed_struct(AstNode *snode, int base_offset)
                                save_struct_array_width(node, width);
                                width *= array_count;
                                // range nodes are now redundant
+                               for (AstNode *child : node->children)
+                                       delete child;
                                node->children.clear();
                        }
                        else if (node->range_left < 0) {
@@ -5052,6 +5056,9 @@ finished:
 void AstNode::allocateDefaultEnumValues()
 {
        log_assert(type==AST_ENUM);
+       log_assert(children.size() > 0);
+       if (children.front()->attributes.count(ID::enum_base_type))
+               return; // already elaborated
        int last_enum_int = -1;
        for (auto node : children) {
                log_assert(node->type==AST_ENUM_ITEM);
index 120a8bca3ccaa495e651c033ae89d5486051fb4c..9558b0e873c2b0bf68d5dc23008c6a4196d2613c 100644 (file)
@@ -1711,10 +1711,12 @@ member_type_token:
                        delete astbuf1;
                        astbuf1 = template_node;
                }
-       | struct_union {
+       | {
+               delete astbuf1;
+       } struct_union {
                        // stash state on ast_stack
                        ast_stack.push_back(astbuf2);
-                       astbuf2 = $1;
+                       astbuf2 = $2;
                } struct_body  {
                        astbuf1 = astbuf2;
                        // recover state