[PATCH] [RFC] Add g_*_deinit() API



I'm currently working on adding API to GLib/GObject/GIO for explicitly
cleaning up statically allocated resources, like TLS keys, threads,
handles, heap blocks, etc.

This is clearly not useful to regular GLib-based applications where
GLib has the same life-time as the host process itself, so such
applications/libraries will behave just like before, because they
won't be calling any deinit functions at exit/unload.  However, in
certain applications, like for example Frida
(http://code.google.com/p/frida-ire/), there is a shared library which
has its own private copy of GLib/GObject/GIO statically linked in, and
this library gets injected into already running applications in order
to do runtime instrumentation of APIs and things like that. When the
user of the controlling application which injected the shared library
decides it wants to detach, the controlling application signals this
to the injected code running inside the target process, which makes it
shut itself down and eventually dlclose()/FreeLibrary() unloads that
library. This works really well thanks to Vala, GDBus and a bunch of
other excellent G components that makes this really easy, but, there
is a problem. Each time the library is loaded it will initialize GLib
and friends, and resources will get claimed, but never released. So if
you inject a sufficient amount of times you will eventually make the
target application run out of OS resources. So, this calls for some
way to clean things up.

I'm finally nearing completion on a patch which implements this, and
am keeping it here:
http://gitorious.org/frida/glib/commits/master

It's still work in progress as it, off the top of my head:
- lacks documentation
- need to redo the GThread POSIX backend to not use any gmem stuff
- should probably be split into multiple patches (one for each of
GLib, GThread, GIO, etc.)
- should probably merge the gio*private.h files into gioprivate.h

But, I would really appreciate feedback on this, and whether any of
you GLib maintainers think it is feasible to get this upstream at some
point. Thoughts, anyone?

Cheers,
Ole André


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]