plugin.c (try_init_one_plugin): Fix ressource leaks (CID 726637)
authorSylvestre Ledru <sylvestre@debian.org>
Tue, 16 May 2017 07:44:33 +0000 (07:44 +0000)
committerSylvestre Ledru <sylvestre@gcc.gnu.org>
Tue, 16 May 2017 07:44:33 +0000 (07:44 +0000)
From-SVN: r248088

gcc/ChangeLog
gcc/plugin.c

index f94e442..48f1bee 100644 (file)
@@ -1,3 +1,7 @@
+2017-05-15  Sylvestre Ledru  <sylvestre@debian.org>
+
+       plugin.c (try_init_one_plugin): Fix ressource leaks (CID 726637)
+
 2017-05-15  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/80425
index cfd6ef2..c6d3cdd 100644 (file)
@@ -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);
       error ("fail to initialize plugin %s", plugin->full_name);
       return false;
     }
-
+  /* leak dl_handle on purpose to ensure the plugin is loaded for the
+     entire run of the compiler. */
   return true;
 }