mono_lookup_pinvoke_call: prevent leak by keeping a global MonoDl handle for the...
authorMiguel de Icaza <miguel@gnome.org>
Thu, 19 Jul 2012 02:25:00 +0000 (22:25 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 19 Jul 2012 02:27:21 +0000 (22:27 -0400)
From now on, we will keep a global handle for lookups performed against the "__Internal"
library name.   This will prevent multiple P/Invoke calls from calling mono_dl_open with
filename == NULL for each call.

Since Mono never calls mono_dl_close on P/Invoke lookups, this should not pose a problem.

mono/metadata/loader.c

index 69578884713e17adcb1a0940ff0d6e28dc13cf0a..ab0c3223bcdc3e1f8c16878015b07ee116b1de6f 100644 (file)
@@ -1285,6 +1285,8 @@ cached_module_load (const char *name, int flags, char **err)
        return res;
 }
 
+static MonoDl *internal_module;
+
 gpointer
 mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char **exc_arg)
 {
@@ -1361,8 +1363,11 @@ mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char
                                        "DllImport attempting to load: '%s'.", new_scope);
 
                /* we allow a special name to dlopen from the running process namespace */
-               if (strcmp (new_scope, "__Internal") == 0)
-                       module = mono_dl_open (NULL, MONO_DL_LAZY, &error_msg);
+               if (strcmp (new_scope, "__Internal") == 0){
+                       if (internal_module == NULL)
+                               internal_module = mono_dl_open (NULL, MONO_DL_LAZY, &error_msg);
+                       module = internal_module;
+               }
        }
 
        /*