]> git.draconx.ca Git - cdecl99.git/commitdiff
Plug memory leak in declgen.
authorNick Bowler <nbowler@draconx.ca>
Thu, 10 Feb 2022 01:37:50 +0000 (20:37 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 10 Feb 2022 01:52:49 +0000 (20:52 -0500)
When a void typespec is generated in a context where it is invalid,
gen_typespecs just rolls the dice again.  Unfortunately, the typespec
is not freed in this case, leaking memory.  Easily fixed.

test/declgen.c

index 221c71ac247e885cf834fa86a4a6e4264a4a3bcb..0e76348c84c352acbf280bd206d3e4e1bbf6136d 100644 (file)
@@ -183,8 +183,11 @@ retry:
        switch (specs->type) {
        /* void is not always valid, so we might need to pick again. */
        case CDECL_TYPE_VOID:
-               if (!voidtype)
+               if (!voidtype) {
+                       assert(!specs->next);
+                       free(specs);
                        goto retry;
+               }
                break;
        /* A few kinds of type specifiers need identifiers to go with them. */
        case CDECL_TYPE_STRUCT: