1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

flashrom.c: Replace 'exit(1)' leaks with return codes on err paths

Do not just exit in the middle of the process, rather return
a value back up to the caller to allow proper resource cleanup's
to occur.

Change-Id: Ie4186a40071e9a7296d601582ff15ad7df09c70a
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/69474
Reviewed-by: Felix Singer <felixsinger@posteo.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Edward O'Callaghan 2022-11-12 12:08:46 +11:00 committed by Felix Singer
parent 4e27cad44d
commit 6352f8b3df

View File

@ -319,7 +319,7 @@ static char *extract_param(char *const *haystack, const char *needle, const char
opt = malloc(optlen + 1); opt = malloc(optlen + 1);
if (!opt) { if (!opt) {
msg_gerr("Out of memory!\n"); msg_gerr("Out of memory!\n");
exit(1); return NULL;
} }
strncpy(opt, opt_pos, optlen); strncpy(opt, opt_pos, optlen);
opt[optlen] = '\0'; opt[optlen] = '\0';
@ -455,7 +455,7 @@ static int check_erased_range(struct flashctx *flash, unsigned int start, unsign
if (!cmpbuf) { if (!cmpbuf) {
msg_gerr("Out of memory!\n"); msg_gerr("Out of memory!\n");
exit(1); return -1;
} }
memset(cmpbuf, erased_value, len); memset(cmpbuf, erased_value, len);
ret = verify_range(flash, cmpbuf, start, len); ret = verify_range(flash, cmpbuf, start, len);
@ -897,7 +897,7 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
flash->chip = calloc(1, sizeof(*flash->chip)); flash->chip = calloc(1, sizeof(*flash->chip));
if (!flash->chip) { if (!flash->chip) {
msg_gerr("Out of memory!\n"); msg_gerr("Out of memory!\n");
exit(1); return -1;
} }
*flash->chip = *chip; *flash->chip = *chip;
flash->mst = mst; flash->mst = mst;