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)
This commit is contained in:
Furquan Shaikh 2016-08-05 12:04:55 -07:00 committed by Patrick Georgi
parent f3bba44a04
commit b927bec09a
2 changed files with 6 additions and 0 deletions

View File

@ -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 * Clean up any internal state represented by ew. Aftewards the elf_writer
* is invalid. * 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) void elf_writer_destroy(struct elf_writer *ew)
{ {
int i; int i;
if (ew == NULL)
return;
if (ew->phdrs != NULL) if (ew->phdrs != NULL)
free(ew->phdrs); free(ew->phdrs);
free(ew->strtab.buffer); free(ew->strtab.buffer);

View File

@ -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 * Clean up any internal state represented by ew. Aftewards the elf_writer
* is invalid. * 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); void elf_writer_destroy(struct elf_writer *ew);