This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: PR gold/17896: Plugin_manager::release_input_file leaks file descriptors


This patch makes Plugin_manager::release_input_file to release file
descriptor.  OK to install?

Thanks.


H.J.
---
>From 534bb2e44556ea2afd1d9336fa103a3432b9fb56 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 28 Jan 2015 10:05:17 -0800
Subject: [PATCH] Release file descriptor in release_input_file

Plugin_manager::release_input_file should release file descriptor.

	PR gold/17896
	* plugin.cc: Include <unistd.h> and <cerrno>.
	(Plugin_manager::release_input_file): Close file descriptor when
	called from the claim_file hook.  Otherwise, release the object.
---
 gold/ChangeLog |  7 +++++++
 gold/plugin.cc | 28 ++++++++++++++++++++++------
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/gold/ChangeLog b/gold/ChangeLog
index 946504a..3dbbf94 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-28  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gold/17896
+	* plugin.cc: Include <unistd.h> and <cerrno>.
+	(Plugin_manager::release_input_file): Close file descriptor when
+	called from the claim_file hook.  Otherwise, release the object.
+
 2015-01-25  Cary Coutant  <ccoutant@google.com>
 
 	* output.cc (Output_segment::set_section_addresses): Fix calculation
diff --git a/gold/plugin.cc b/gold/plugin.cc
index bde8c78..7c0b1e3 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -22,6 +22,8 @@
 
 #include "gold.h"
 
+#include <unistd.h>
+#include <cerrno>
 #include <cstdio>
 #include <cstdarg>
 #include <cstring>
@@ -767,15 +769,29 @@ Plugin_manager::get_input_file(unsigned int handle,
 ld_plugin_status
 Plugin_manager::release_input_file(unsigned int handle)
 {
-  if (this->object(handle) == NULL)
-    return LDPS_BAD_HANDLE;
+  if (this->in_claim_file_handler_)
+    {
+      // We are being called from the claim_file hook.
+      const struct ld_plugin_input_file &f = this->plugin_input_file_;
+    if (::close(f.fd) < 0)
+      {
+	gold_error(_("%s: close: %s"), f.name, strerror(errno));
+	return LDPS_ERR;
+      }
+    }
+  else
+    {
+      if (this->object(handle) == NULL)
+	return LDPS_BAD_HANDLE;
 
-  Pluginobj* obj = this->object(handle)->pluginobj();
+      Pluginobj* obj = this->object(handle)->pluginobj();
 
-  if (obj == NULL)
-    return LDPS_BAD_HANDLE;
+      if (obj == NULL)
+	return LDPS_BAD_HANDLE;
 
-  obj->unlock(this->task_);
+      obj->release();
+      obj->unlock(this->task_);
+    }
   return LDPS_OK;
 }
 
-- 
1.9.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]