This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR gold/17896: Plugin_manager::release_input_file leaks file descriptors
- From: Rafael EspÃndola <rafael dot espindola at gmail dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>, Cary Coutant <ccoutant at google dot com>
- Date: Wed, 28 Jan 2015 18:45:44 +0000
- Subject: Re: PATCH: PR gold/17896: Plugin_manager::release_input_file leaks file descriptors
- Authentication-results: sourceware.org; auth=none
- References: <20150128180803 dot GA15015 at intel dot com>
BTW,
you might also be interested in
https://sourceware.org/bugzilla/show_bug.cgi?id=15660.
On 28 January 2015 at 18:08, H.J. Lu <hongjiu.lu@intel.com> wrote:
> 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
>