This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] plugin.c (try_init_one_plugin): Fix ressource leaks (CID 726637)
- From: Sylvestre Ledru <sylvestre at debian dot org>
- To: Trevor Saunders <tbsaunde at tbsaunde dot org>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sun, 14 May 2017 17:30:36 +0200
- Subject: Re: [PATCH] plugin.c (try_init_one_plugin): Fix ressource leaks (CID 726637)
- Authentication-results: sourceware.org; auth=none
- References: <0cf142a9-7447-057a-6ac9-f76ef69b84ee@debian.org> <20170514103749.4xjssjoaeemw57fx@ball>
Le 14/05/2017 à 12:40, Trevor Saunders a écrit :
> On Sun, May 14, 2017 at 11:59:40AM +0200, Sylvestre Ledru wrote:
>> Add missing dlclose()
>>
>> S
>>
>>
>> From d0926b84047f281a29dc51bbd0a4bdda01a5c63f Mon Sep 17 00:00:00 2001
>> From: Sylvestre Ledru <sylvestre@debian.org>
>> Date: Sun, 14 May 2017 11:28:38 +0200
>> Subject: [PATCH 4/5] 2017-05-14 Sylvestre Ledru <sylvestre@debian.org>
>>
>> * plugin.c (try_init_one_plugin): Fix ressource leaks (CID 726637)
>> ---
>> gcc/plugin.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/gcc/plugin.c b/gcc/plugin.c
>> index cfd6ef25036..903a197b78b 100644
>> --- a/gcc/plugin.c
>> +++ b/gcc/plugin.c
>> @@ -617,6 +617,7 @@ try_init_one_plugin (struct plugin_name_args *plugin)
>>
>> if ((err = dlerror ()) != NULL)
>> {
>> + dlclose(dl_handle);
>> error ("cannot find %s in plugin %s\n%s", str_plugin_init_func_name,
>> plugin->full_name, err);
>> return false;
>> @@ -625,10 +626,12 @@ try_init_one_plugin (struct plugin_name_args *plugin)
>> /* Call the plugin-provided initialization routine with the arguments. */
>> if ((*plugin_init) (plugin, &gcc_version))
>> {
>> + dlclose(dl_handle);
> These seem like unimportant, but real leaks so they seem correct.
>
>> error ("fail to initialize plugin %s", plugin->full_name);
>> return false;
>> }
>>
>> + dlclose(dl_handle);
> Does this part pass the plugin tests? because it seems suspicious, if
> the plugin's init function registered any callbacks which it almost
> certainly did, then we'd be holding function pointers into the plugin
> after we dlclosed our only reference to it. We don't need to call any
> more functions with the handle, but I think we want to morally leak it
> here to ensure the plugin is loaded for the entire run of the compiler.
>
Indeed, false positive marked in the coverity interface.
New patch attached
S
>From 08f3fb989f6b6ee56e1d4d9674e743dd563a0904 Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <sylvestre@debian.org>
Date: Sun, 14 May 2017 11:28:38 +0200
Subject: [PATCH 1/2] 2017-05-14 Sylvestre Ledru <sylvestre@debian.org>
* plugin.c (try_init_one_plugin): Fix ressource leaks (CID 726637)
---
gcc/plugin.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gcc/plugin.c b/gcc/plugin.c
index cfd6ef25036..60d037c2b83 100644
--- a/gcc/plugin.c
+++ b/gcc/plugin.c
@@ -617,6 +617,7 @@ try_init_one_plugin (struct plugin_name_args *plugin)
if ((err = dlerror ()) != NULL)
{
+ dlclose(dl_handle);
error ("cannot find %s in plugin %s\n%s", str_plugin_init_func_name,
plugin->full_name, err);
return false;
@@ -625,6 +626,7 @@ try_init_one_plugin (struct plugin_name_args *plugin)
/* Call the plugin-provided initialization routine with the arguments. */
if ((*plugin_init) (plugin, &gcc_version))
{
+ dlclose(dl_handle);
error ("fail to initialize plugin %s", plugin->full_name);
return false;
}
--
2.11.0