Close fd only if fd != -1
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 6 Feb 2015 00:57:09 +0000 (16:57 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 6 Feb 2015 00:57:09 +0000 (16:57 -0800)
This patch closes fd only if fd != -1.

* plugin.c (release_input_file): Set fd to -1 after closing it.
(plugin_maybe_claim): Close fd only if fd != -1.

ld/ChangeLog
ld/plugin.c

index 0d767babe4dfcda2ba866b47c1d56f25d0dd1224..4ae174b29b0e4580be6f7aa5780c99dc3c61cca7 100644 (file)
@@ -1,3 +1,8 @@
+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
index 28236f2404b7cfd68cc04243c6a938d7ec5144dd..ae0ac8976c4df30907849143c5a9a3f8f6338c94 100644 (file)
@@ -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
This page took 0.026947 seconds and 4 git commands to generate.