scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 6c44531003e21a540421fc73a382d6f7b3520cbd
parent 9197be5ac4cb884d119aed4d5b0c66d602c9614b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 17 Nov 2014 03:54:03 -0500

Free data parameter of mktype when type already exits

When the type already exits we don't store it in the type hash, but the
data need to be allocated in the head due to the recursive decl parser.
If we don't use this data because type already exits, then we must
free it.

Diffstat:
cc1/decl.c | 1-
cc1/types.c | 4+++-
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -67,7 +67,6 @@ fundcl(struct dcldata *dp) expect(')'); if (n != 0) { - /* TODO: leak when type already exits (also in structs) */ siz = sizeof(*tp) * n; tp = (siz > 0) ? memcpy(xmalloc(siz), pars, siz) : NULL; } diff --git a/cc1/types.c b/cc1/types.c @@ -216,8 +216,10 @@ mktype(Type *tp, uint8_t op, short nelem, void *data) t = (op ^ (uint8_t) ((unsigned short) tp >> 3)) & NR_TYPE_HASH-1; tbl = &typetab[t]; for (bp = *tbl; bp; bp = bp->next) { - if (eqtype(bp, &type)) + if (eqtype(bp, &type)) { + free(data); return bp; + } } bp = xmalloc(sizeof(*bp));