diff options
author | Alan Modra <amodra@gmail.com> | 2025-01-01 22:52:06 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2025-01-01 22:52:06 +1030 |
commit | 4739b9137e1fe1cfaf2e0de6924c122035942b26 (patch) | |
tree | 25ade2d868896b772fc4c80f32bb7a8285cc9a4a | |
parent | d58fbef40d70057b83d3773aa409b402236a7e62 (diff) | |
download | gdb-4739b9137e1fe1cfaf2e0de6924c122035942b26.zip gdb-4739b9137e1fe1cfaf2e0de6924c122035942b26.tar.gz gdb-4739b9137e1fe1cfaf2e0de6924c122035942b26.tar.bz2 |
Close elements of output archive
When cleaning up an archive, close all its elements. This fixes a
number of ar memory leaks.
bfd/
* archive.c (_bfd_archive_close_and_cleanup): Close elements
of an archive open for writing.
binutils/
* objcopy.c (copy_archive): Don't close output archive
elements here.
* dlltool.c (gen_lib_file): Likewise.
ld/
* pe-dll.c (pe_dll_generate_implib): Don't close output
archive elements here.
-rw-r--r-- | bfd/archive.c | 9 | ||||
-rw-r--r-- | binutils/dlltool.c | 7 | ||||
-rw-r--r-- | binutils/objcopy.c | 5 | ||||
-rw-r--r-- | ld/pe-dll.c | 7 |
4 files changed, 10 insertions, 18 deletions
diff --git a/bfd/archive.c b/bfd/archive.c index b3019e2..ef01095 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -2882,6 +2882,15 @@ _bfd_unlink_from_archive_parent (bfd *abfd) bool _bfd_archive_close_and_cleanup (bfd *abfd) { + if (bfd_write_p (abfd) && abfd->format == bfd_archive) + { + bfd *current; + while ((current = abfd->archive_head) != NULL) + { + abfd->archive_head = current->archive_next; + bfd_close_all_done (current); + } + } if (bfd_read_p (abfd) && abfd->format == bfd_archive) { bfd *nbfd; diff --git a/binutils/dlltool.c b/binutils/dlltool.c index 4426aae..d32bf20 100644 --- a/binutils/dlltool.c +++ b/binutils/dlltool.c @@ -3009,13 +3009,6 @@ gen_lib_file (int delay) if (! bfd_close (outarch)) bfd_fatal (imp_name); - while (head != NULL) - { - bfd *n = head->archive_next; - bfd_close (head); - head = n; - } - /* Delete all the temp files. */ unlink_temp_files (); diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 10539ed..f644176 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3845,10 +3845,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, if (l->obfd == NULL) rmdir (l->name); else - { - bfd_close (l->obfd); - unlink (l->name); - } + unlink (l->name); free (l->name); } next = l->next; diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 2b2ef68..d888a0b 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -3058,13 +3058,6 @@ pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_ if (! bfd_close (outarch)) einfo ("%X%P: bfd_close %s: %E\n", impfilename); - - while (head != NULL) - { - bfd *n = head->archive_next; - bfd_close (head); - head = n; - } } static int undef_count = 0; |