Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Nikolai Artemiev: Looks good to me, but someone else must approve
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>
---
M libflashrom.c
1 file changed, 3 insertions(+), 0 deletions(-)

diff --git a/libflashrom.c b/libflashrom.c
index d66c295..5f14c68 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -361,6 +361,9 @@
*/
void flashrom_flash_release(struct flashrom_flashctx *const flashctx)
{
+ if (!flashctx)
+ return;
+
flashrom_layout_release(flashctx->default_layout);
free(flashctx->chip);
free(flashctx);

To view, visit change 62340. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Id119c2e4f3aa1b11313059f11aac73c3e583185c
Gerrit-Change-Number: 62340
Gerrit-PatchSet: 2
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Nikolai Artemiev <nartemiev@google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged