From c68645cd88a2c72c14b71ad1a590b9e1edf13a6e Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Sun, 6 Jul 2025 12:01:55 -0600 Subject: [PATCH] util/supermicro: Fix mem leak in get_line_as_int error conditions When parsing the string, if it doesn't end with 0 or \n, get_line_as_int returns -1, but wasn't freeing the buffer. Also if we got an empty string with just null termination, that byte would also cause a leak, so move the second free() to the bottom. It's always fine to free a null pointer if the allocation failed. BUG=CID 1419489 Change-Id: Ibb3a7544ec8c46820b6e47b6fd4bbe5cabafe1a8 Signed-off-by: Martin Roth Reviewed-on: https://review.coreboot.org/c/coreboot/+/88335 Reviewed-by: Elyes Haouas Tested-by: build bot (Jenkins) --- util/supermicro/smcbiosinfo/smcbiosinfo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/supermicro/smcbiosinfo/smcbiosinfo.c b/util/supermicro/smcbiosinfo/smcbiosinfo.c index 6a27ba7a77..c55cb46013 100644 --- a/util/supermicro/smcbiosinfo/smcbiosinfo.c +++ b/util/supermicro/smcbiosinfo/smcbiosinfo.c @@ -101,15 +101,16 @@ static int get_line_as_int(char *fn, char *match, int bcd) ret = strtol(s, &endptr, 0); if (*endptr != '\0' && *endptr != '\n') { fprintf(stderr, "E: Couldn't parse number for key '%s'\n", match); + free(s); return -1; } if (bcd) ret = bcd2int(ret); - free(s); } else { fprintf(stderr, "E: Got invalid line for key '%s'\n", match); } + free(s); return ret; }