From 4739b9137e1fe1cfaf2e0de6924c122035942b26 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 1 Jan 2025 22:52:06 +1030 Subject: 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. --- binutils/dlltool.c | 7 ------- binutils/objcopy.c | 5 +---- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'binutils') 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; -- cgit v1.1