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 <gaumless@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/88335 Reviewed-by: Elyes Haouas <ehaouas@noos.fr> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
05396238da
commit
c68645cd88
1 changed files with 2 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue