From b927bec09a09d96e44247b16fb1171efe6744f65 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Fri, 5 Aug 2016 12:04:55 -0700 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/16076 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- util/cbfstool/elfheaders.c | 4 ++++ util/cbfstool/elfparsing.h | 2 ++ 2 files changed, 6 insertions(+) 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);