* [binutils-gdb] Don't access freed memory printing objcopy warning
@ 2022-12-14 3:36 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-12-14 3:36 UTC (permalink / raw)
To: bfd-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bd5efa59305b4f84da4d7ece171acf37ee2c99a4
commit bd5efa59305b4f84da4d7ece171acf37ee2c99a4
Author: Alan Modra <amodra@gmail.com>
Date: Wed Dec 14 11:42:00 2022 +1030
Don't access freed memory printing objcopy warning
abfd->filename will be freed if bfd_close gets far enough to delete
the bfd. It's possible to have an error from fclose at this point.
* objcopy.c (copy_archive): Dup filename before closing bfd for
potential use in bfd_nonfatal_message.
Diff:
---
binutils/objcopy.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index be08f7bd0f9..289b62355af 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3543,7 +3543,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
bfd **ptr = &obfd->archive_head;
bfd *this_element;
char *dir;
- const char *filename;
+ char *filename;
/* PR 24281: It is not clear what should happen when copying a thin archive.
One part is straight forward - if the output archive is in a different
@@ -3720,19 +3720,21 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
}
*ptr = NULL;
- filename = bfd_get_filename (obfd);
+ filename = xstrdup (bfd_get_filename (obfd));
if (!(status == 0 ? bfd_close : bfd_close_all_done) (obfd))
{
status = 1;
bfd_nonfatal_message (filename, NULL, NULL, NULL);
}
+ free (filename);
- filename = bfd_get_filename (ibfd);
+ filename = xstrdup (bfd_get_filename (ibfd));
if (!bfd_close (ibfd))
{
status = 1;
bfd_nonfatal_message (filename, NULL, NULL, NULL);
}
+ free (filename);
cleanup_and_exit:
/* Delete all the files that we opened. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-14 3:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14 3:36 [binutils-gdb] Don't access freed memory printing objcopy warning Alan Modra
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).