This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[committed, PATCH] Close fd only if fd != -1
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Thu, 5 Feb 2015 16:59:42 -0800
- Subject: [committed, PATCH] Close fd only if fd != -1
- Authentication-results: sourceware.org; auth=none
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
I checked in this patch to close fd only if fd != -1.
H.J.
* plugin.c (release_input_file): Set fd to -1 after closing it.
(plugin_maybe_claim): Close fd only if fd != -1.
---
ld/ChangeLog | 5 +++++
ld/plugin.c | 9 ++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 0d767ba..4ae174b 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,10 @@
2015-02-05 H.J. Lu <hongjiu.lu@intel.com>
+ * plugin.c (release_input_file): Set fd to -1 after closing it.
+ (plugin_maybe_claim): Close fd only if fd != -1.
+
+2015-02-05 H.J. Lu <hongjiu.lu@intel.com>
+
PR ld/17878
* plugin.c: Include <errno.h>.
(errno): New. Declare if needed.
diff --git a/ld/plugin.c b/ld/plugin.c
index 28236f2..ae0ac89 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -512,10 +512,13 @@ get_view (const void *handle, const void **viewp)
static enum ld_plugin_status
release_input_file (const void *handle)
{
- const plugin_input_file_t *input = handle;
+ plugin_input_file_t *input = (plugin_input_file_t *) handle;
ASSERT (called_plugin);
if (input->fd != -1)
- close (input->fd);
+ {
+ close (input->fd);
+ input->fd = -1;
+ }
return LDPS_OK;
}
@@ -964,7 +967,7 @@ plugin_maybe_claim (struct ld_plugin_input_file *file,
einfo (_("%P%F: %s: plugin reported error claiming file\n"),
plugin_error_plugin ());
- if (bfd_check_format (entry->the_bfd, bfd_object))
+ if (input->fd != -1 && bfd_check_format (entry->the_bfd, bfd_object))
{
/* FIXME: fd belongs to us, not the plugin. IR for GCC plugin,
which doesn't need fd after plugin_call_claim_file, is
--
1.9.3