| 1 | --- gmodule/gmodule-dl.c.orig 2014-07-04 16:59:10.000000000 -0700 |
| 2 | +++ gmodule/gmodule-dl.c 2014-11-03 10:53:31.000000000 -0800 |
| 3 | @@ -126,16 +126,18 @@ static void |
| 4 | _g_module_close (gpointer handle, |
| 5 | gboolean is_unref) |
| 6 | { |
| 7 | - /* are there any systems out there that have dlopen()/dlclose() |
| 8 | - * without a reference count implementation? |
| 9 | + /* Intentionally not dlclose()ing because it is safer to leave the library |
| 10 | + * loaded in memory than to close it and possibly leave dangling pointers |
| 11 | + * to things like atexit handlers, atfork handlers, blocks, etc. |
| 12 | + * |
| 13 | + * See https://trac.macports.org/ticket/45309 for an example from when |
| 14 | + * a library used by a module added a new dependency which had an |
| 15 | + * initializer which added a child atfork handler. The result is that |
| 16 | + * after closing the module, the system had a dangling pointer for the |
| 17 | + * atfork handler which would at best crash on the child side of fork() |
| 18 | + * and at worst lead to arbitray code execution of whatever happened to be |
| 19 | + * at that location in memory at a later time in the process. |
| 20 | */ |
| 21 | - is_unref |= 1; |
| 22 | - |
| 23 | - if (is_unref) |
| 24 | - { |
| 25 | - if (dlclose (handle) != 0) |
| 26 | - g_module_set_error (fetch_dlerror (TRUE)); |
| 27 | - } |
| 28 | } |
| 29 | |
| 30 | static gpointer |