--- gmodule/gmodule-dl.c.orig 2017-10-27 19:42:55.000000000 -0500
+++ gmodule/gmodule-dl.c 2017-11-22 21:54:27.000000000 -0600
_g_module_close (gpointer handle,
- /* are there any systems out there that have dlopen()/dlclose()
- * without a reference count implementation?
+ /* Intentionally not dlclose()ing because it is safer to leave the library
+ * loaded in memory than to close it and possibly leave dangling pointers
+ * to things like atexit handlers, atfork handlers, blocks, etc.
- * See above for the Android special case
+ * See https://trac.macports.org/ticket/45309 for an example from when
+ * a library used by a module added a new dependency which had an
+ * initializer which added a child atfork handler. The result is that
+ * after closing the module, the system had a dangling pointer for the
+ * atfork handler which would at best crash on the child side of fork()
+ * and at worst lead to arbitrary code execution of whatever happened to be
+ * at that location in memory at a later time in the process.
- is_unref = (handle != RTLD_DEFAULT);
- if (dlclose (handle) != 0)
- g_module_set_error (fetch_dlerror (TRUE));