From d05712529045e1694a834d57b0346c0b92a8735a Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Mon, 2 Jan 2017 19:24:48 +0100 Subject: util/romcc: avoid leaking a type Only allocate ptr_type when it's actually used. Change-Id: Iea5f93601a42f02a1866bdff099f63935fdd5b8d Signed-off-by: Patrick Georgi Found-by: Coverity Scan #1129117 Reviewed-on: https://review.coreboot.org/18017 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth --- util/romcc/romcc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'util/romcc') diff --git a/util/romcc/romcc.c b/util/romcc/romcc.c index 62fe758ef6..c2f5deed6c 100644 --- a/util/romcc/romcc.c +++ b/util/romcc/romcc.c @@ -7266,22 +7266,25 @@ static struct triple *do_mk_addr_expr(struct compile_state *state, struct triple *expr, struct type *type, ulong_t offset) { struct triple *result; - struct type *ptr_type; clvalue(state, expr); - ptr_type = new_type(TYPE_POINTER | (type->type & QUAL_MASK), type, 0); - result = 0; if (expr->op == OP_ADECL) { error(state, expr, "address of auto variables not supported"); } else if (expr->op == OP_SDECL) { + struct type *ptr_type; + ptr_type = new_type(TYPE_POINTER | (type->type & QUAL_MASK), type, 0); + result = triple(state, OP_ADDRCONST, ptr_type, 0, 0); MISC(result, 0) = expr; result->u.cval = offset; } else if (expr->op == OP_DEREF) { + struct type *ptr_type; + ptr_type = new_type(TYPE_POINTER | (type->type & QUAL_MASK), type, 0); + result = triple(state, OP_ADD, ptr_type, RHS(expr, 0), int_const(state, &ulong_type, offset)); -- cgit v1.2.3