[PATCH] plugin.c (try_init_one_plugin): Fix ressource leaks (CID 726637)

Jeff Law law@redhat.com
Mon May 15 22:14:00 GMT 2017


On 05/14/2017 09:30 AM, Sylvestre Ledru wrote:
> 
> 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
> 
> 
> 0001-2017-05-14-Sylvestre-Ledru-sylvestre-debian.org.patch
> 
> 
>  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)
The second version is fine.

jeff



More information about the Gcc-patches mailing list