summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2016-08-05 12:04:55 -0700
committerPatrick Georgi <pgeorgi@google.com>2016-08-08 13:01:34 +0200
commitb927bec09a09d96e44247b16fb1171efe6744f65 (patch)
treecde7209eb6b957a0d208383095a05e296e572c2d
parentf3bba44a04a966198ed0896f3b516e1d5909769b (diff)
downloadcoreboot-b927bec09a09d96e44247b16fb1171efe6744f65.tar.xz
cbfstool/elfheaders: Make elf_writer_destroy NULL-safe
This relieves caller from having to check if the parameter being passed in is NULL. Change-Id: I3ea935c12d46c6fb5534e0f2077232b9e25240f1 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/16076 Reviewed-by: Aaron Durbin <adurbin@chromium.org> Tested-by: build bot (Jenkins)
-rw-r--r--util/cbfstool/elfheaders.c4
-rw-r--r--util/cbfstool/elfparsing.h2
2 files changed, 6 insertions, 0 deletions
diff --git a/util/cbfstool/elfheaders.c b/util/cbfstool/elfheaders.c
index 8942eea03c..0462d0a6d6 100644
--- a/util/cbfstool/elfheaders.c
+++ b/util/cbfstool/elfheaders.c
@@ -808,10 +808,14 @@ struct elf_writer *elf_writer_init(const Elf64_Ehdr *ehdr)
/*
* Clean up any internal state represented by ew. Aftewards the elf_writer
* is invalid.
+ * It is safe to call elf_writer_destroy with ew as NULL. It returns without
+ * performing any action.
*/
void elf_writer_destroy(struct elf_writer *ew)
{
int i;
+ if (ew == NULL)
+ return;
if (ew->phdrs != NULL)
free(ew->phdrs);
free(ew->strtab.buffer);
diff --git a/util/cbfstool/elfparsing.h b/util/cbfstool/elfparsing.h
index 4b9ba8d434..978592bc46 100644
--- a/util/cbfstool/elfparsing.h
+++ b/util/cbfstool/elfparsing.h
@@ -93,6 +93,8 @@ struct elf_writer *elf_writer_init(const Elf64_Ehdr *ehdr);
/*
* Clean up any internal state represented by ew. Aftewards the elf_writer
* is invalid.
+ * It is safe to call elf_writer_destroy with ew as NULL. It returns without
+ * performing any action.
*/
void elf_writer_destroy(struct elf_writer *ew);