ref: 6c44531003e21a540421fc73a382d6f7b3520cbd
parent: 9197be5ac4cb884d119aed4d5b0c66d602c9614b
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Nov 16 22:54:03 EST 2014
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.
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -67,7 +67,6 @@
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;
}
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -216,8 +216,10 @@
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));