From 9cc6be205dce4cb67de3c1202bdd0769547ede22 Mon Sep 17 00:00:00 2001 From: Anastasia Klimchuk Date: Sun, 3 Mar 2024 19:47:22 +1100 Subject: 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 Reviewed-on: https://review.coreboot.org/c/flashrom/+/81032 Tested-by: build bot (Jenkins) Reviewed-by: Alexander Goncharov Reviewed-by: Stefan Reinauer --- serprog.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'serprog.c') diff --git a/serprog.c b/serprog.c index c2965c52b..f738ef356 100644 --- a/serprog.c +++ b/serprog.c @@ -835,9 +835,9 @@ static int serprog_init(const struct programmer_cfg *cfg) free(cs); goto init_err_cleanup_exit; } - free(cs); if (!sp_check_commandavail(S_CMD_S_SPI_CS)) { msg_perr("Error: Setting SPI chip select is not supported!\n"); + free(cs); goto init_err_cleanup_exit; } 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)) { msg_perr("Error: Chip select %u not supported " "by programmer!\n", cs_num8); + free(cs); goto init_err_cleanup_exit; } } + free(cs); + bt = serprog_buses_supported; if (sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL)) goto init_err_cleanup_exit; -- cgit v1.2.3