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);