--- gmodule/gmodule-dl.c.orig	2025-12-08 10:46:06
+++ gmodule/gmodule-dl.c	2026-02-10 11:45:30
@@ -182,15 +182,18 @@
 static void
 _g_module_close (gpointer handle)
 {
-#if defined(__ANDROID__) || 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
