aboutsummaryrefslogtreecommitdiff
path: root/bfd/plugin.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-07-26 05:59:55 -0700
committerH.J. Lu <hjl.tools@gmail.com>2021-07-28 06:01:32 -0700
commit5a98fb7513b559e20dfebdbaa2a471afda3b4742 (patch)
tree9afa418dac0808e77bfa34eaa1fe719b08e4725e /bfd/plugin.c
parent265dcb69c2ec6e9f24f40cb25349534e44360098 (diff)
downloadbinutils-5a98fb7513b559e20dfebdbaa2a471afda3b4742.zip
binutils-5a98fb7513b559e20dfebdbaa2a471afda3b4742.tar.gz
binutils-5a98fb7513b559e20dfebdbaa2a471afda3b4742.tar.bz2
bfd: Close the file descriptor if there is no archive fd
Close the file descriptor if there is no archive plugin file descriptor to avoid running out of file descriptors on thin archives with many archive members. bfd/ PR ld/28138 * plugin.c (bfd_plugin_close_file_descriptor): Close the file descriptor there is no archive plugin file descriptor. ld/ PR ld/28138 * testsuite/ld-plugin/lto.exp: Run ld/28138 tests. * testsuite/ld-plugin/pr28138.c: New file. * testsuite/ld-plugin/pr28138-1.c: Likewise. * testsuite/ld-plugin/pr28138-2.c: Likewise. * testsuite/ld-plugin/pr28138-3.c: Likewise. * testsuite/ld-plugin/pr28138-4.c: Likewise. * testsuite/ld-plugin/pr28138-5.c: Likewise. * testsuite/ld-plugin/pr28138-6.c: Likewise. * testsuite/ld-plugin/pr28138-7.c: Likewise.
Diffstat (limited to 'bfd/plugin.c')
-rw-r--r--bfd/plugin.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/bfd/plugin.c b/bfd/plugin.c
index 6cfa2b6..3bab8fe 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -291,6 +291,14 @@ bfd_plugin_close_file_descriptor (bfd *abfd, int fd)
&& !bfd_is_thin_archive (abfd->my_archive))
abfd = abfd->my_archive;
+ /* Close the file descriptor if there is no archive plugin file
+ descriptor. */
+ if (abfd->archive_plugin_fd == -1)
+ {
+ close (fd);
+ return;
+ }
+
abfd->archive_plugin_fd_open_count--;
/* Dup the archive plugin file descriptor for later use, which
will be closed by _bfd_archive_close_and_cleanup. */