From 8d50fad44353b65947e8de42b479ab2fe2256cd5 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Thu, 24 Feb 2022 18:17:40 +0100 Subject: libflashrom: Allow NULL-pointer argument in flashrom_flash_release() free() allows NULL and it makes error paths easier to handle when one just needs to write `free(x);` without needing to care if `x` was allocated already. Let's follow this rule in flashrom_flash_release(). flashrom_layout_release() already checks for NULL. Change-Id: Id119c2e4f3aa1b11313059f11aac73c3e583185c Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/flashrom/+/62340 Tested-by: build bot (Jenkins) Reviewed-by: Nikolai Artemiev Reviewed-by: Felix Singer --- libflashrom.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libflashrom.c') diff --git a/libflashrom.c b/libflashrom.c index d66c29596..5f14c6818 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -361,6 +361,9 @@ size_t flashrom_flash_getsize(const struct flashrom_flashctx *const flashctx) */ void flashrom_flash_release(struct flashrom_flashctx *const flashctx) { + if (!flashctx) + return; + flashrom_layout_release(flashctx->default_layout); free(flashctx->chip); free(flashctx); -- cgit v1.2.3