--- gmodule/gmodule-dl.c.orig 2023-04-18 04:09:54.000000000 +0800 +++ gmodule/gmodule-dl.c 2023-04-18 04:10:21.000000000 +0800 @@ -182,15 +182,18 @@ static void _g_module_close (gpointer handle) { -#if defined(__BIONIC__) || defined(__NetBSD__) - if (handle != RTLD_DEFAULT) -#endif - { - lock_dlerror (); - if (dlclose (handle) != 0) - g_module_set_error (fetch_dlerror (TRUE)); - unlock_dlerror (); - } + /* 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 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. + */ } static gpointer