summaryrefslogtreecommitdiffstats
path: root/libflashrom.c
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2022-02-24 18:17:40 +0100
committerNico Huber <nico.h@gmx.de>2022-02-28 00:47:18 +0000
commit8d50fad44353b65947e8de42b479ab2fe2256cd5 (patch)
tree31846ca359dd84b3b5eb8337d8be22001975d1f5 /libflashrom.c
parent60005a88ea568c64e64b1cdac6ba1bdf1a0ffaee (diff)
downloadflashrom-8d50fad44353b65947e8de42b479ab2fe2256cd5.tar.gz
flashrom-8d50fad44353b65947e8de42b479ab2fe2256cd5.tar.bz2
flashrom-8d50fad44353b65947e8de42b479ab2fe2256cd5.zip
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 <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/flashrom/+/62340 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-by: Felix Singer <felixsinger@posteo.net>
Diffstat (limited to 'libflashrom.c')
-rw-r--r--libflashrom.c3
1 files changed, 3 insertions, 0 deletions
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);