1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

serprog: Fix scan-build warning of resource leak

Warning found by the latest scan-build run:

*** CID 1534883:    (RESOURCE_LEAK)
/serprog.c: 853 in serprog_init()
847                                     "by programmer!\n", cs_num8);
848				goto init_err_cleanup_exit;
849                     }
850             }
851             bt = serprog_buses_supported;
852             if (sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL))
>>>CID 1534883:    (RESOURCE_LEAK)
>>>Variable "cs" going out of scope leaks the storage it points to.
853                     goto init_err_cleanup_exit;
854     }

Follow up on
commit e8c350f55e596aae3ab2bbc210b68389e2301a6c

Change-Id: Id9cf211de3c482f702adebfcfa274a183c83a33f
Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/81032
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Alexander Goncharov <chat@joursoir.net>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Anastasia Klimchuk 2024-03-03 19:47:22 +11:00 committed by Anastasia Klimchuk
parent 54b053e6b2
commit 9cc6be205d

View File

@ -835,9 +835,9 @@ static int serprog_init(const struct programmer_cfg *cfg)
free(cs); free(cs);
goto init_err_cleanup_exit; goto init_err_cleanup_exit;
} }
free(cs);
if (!sp_check_commandavail(S_CMD_S_SPI_CS)) { if (!sp_check_commandavail(S_CMD_S_SPI_CS)) {
msg_perr("Error: Setting SPI chip select is not supported!\n"); msg_perr("Error: Setting SPI chip select is not supported!\n");
free(cs);
goto init_err_cleanup_exit; goto init_err_cleanup_exit;
} }
msg_pdbg(MSGHEADER "Requested to use chip select %lu.\n", cs_num); msg_pdbg(MSGHEADER "Requested to use chip select %lu.\n", cs_num);
@ -845,9 +845,12 @@ static int serprog_init(const struct programmer_cfg *cfg)
if (sp_docommand(S_CMD_S_SPI_CS, 1, &cs_num8, 0, NULL)) { if (sp_docommand(S_CMD_S_SPI_CS, 1, &cs_num8, 0, NULL)) {
msg_perr("Error: Chip select %u not supported " msg_perr("Error: Chip select %u not supported "
"by programmer!\n", cs_num8); "by programmer!\n", cs_num8);
free(cs);
goto init_err_cleanup_exit; goto init_err_cleanup_exit;
} }
} }
free(cs);
bt = serprog_buses_supported; bt = serprog_buses_supported;
if (sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL)) if (sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL))
goto init_err_cleanup_exit; goto init_err_cleanup_exit;