On 05/14/2017 04:40 AM, Trevor Saunders wrote:
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 <sylves...@debian.org>
Date: Sun, 14 May 2017 11:28:38 +0200
Subject: [PATCH 4/5] 2017-05-14  Sylvestre Ledru  <sylves...@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.
One might argue this deserves a comment. Whether or not to add markup to silence Coverity is another issue :-)

jeff

Reply via email to