diff options
author | Alan Modra <amodra@gmail.com> | 2023-01-27 15:16:03 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-01-27 15:46:45 +1030 |
commit | 8219cab3f883cb9981e533407d3ce93d9da7d5f2 (patch) | |
tree | ca38a261183eec8671130af3d7224c29afc1a802 | |
parent | 3e7cde4dca8c63b8091597bd7800f0f71e822395 (diff) | |
download | gdb-8219cab3f883cb9981e533407d3ce93d9da7d5f2.zip gdb-8219cab3f883cb9981e533407d3ce93d9da7d5f2.tar.gz gdb-8219cab3f883cb9981e533407d3ce93d9da7d5f2.tar.bz2 |
Perform cleanup in bfd_close after errors
It seems reasonable to continue after errors in bfd_close_all_done,
particularly since bfd_close_all_done is typically called on an output
file after we've hit some sort of error elsewhere. The iovec test is
necessary if bfd_close_all_done is to work on odd bfd's opened by
bfd_create.
* opncls.c (bfd_close): Call bfd_close_all_done after errors
from _bfd_write_contents.
(bfd_close_all_done): Call _bfd_delete_bfd after errors.
Don't call iovec->bclose when iovec is NULL.
-rw-r--r-- | bfd/opncls.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/bfd/opncls.c b/bfd/opncls.c index 9241cd1..6ae3af0 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -805,13 +805,10 @@ RETURNS bool bfd_close (bfd *abfd) { - if (bfd_write_p (abfd)) - { - if (! BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd))) - return false; - } + bool ret = (!bfd_write_p (abfd) + || BFD_SEND_FMT (abfd, _bfd_write_contents, (abfd))); - return bfd_close_all_done (abfd); + return bfd_close_all_done (abfd) && ret; } /* @@ -839,15 +836,15 @@ RETURNS bool bfd_close_all_done (bfd *abfd) { - bool ret; + bool ret = BFD_SEND (abfd, _close_and_cleanup, (abfd)); - if (! BFD_SEND (abfd, _close_and_cleanup, (abfd))) - return false; - - ret = abfd->iovec->bclose (abfd) == 0; + if (ret && abfd->iovec != NULL) + { + ret = abfd->iovec->bclose (abfd) == 0; - if (ret) - _maybe_make_executable (abfd); + if (ret) + _maybe_make_executable (abfd); + } _bfd_delete_bfd (abfd); |