From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Perform cleanup in bfd_close after errors
Date: Fri, 27 Jan 2023 17:31:56 +1030 [thread overview]
Message-ID: <Y9N25JqhQsKIRAtn@squeak.grove.modra.org> (raw)
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.
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 9241cd1c537..6ae3af054e4 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);
--
Alan Modra
Australia Development Lab, IBM
reply other threads:[~2023-01-27 7:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y9N25JqhQsKIRAtn@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).