GNOME Bugzilla – Bug 609281
pedantic memory freeing
Last modified: 2012-08-26 14:54:26 UTC
on exit, the average glib program contains a lot of things that have been malloc()ed without being freed, by no fault of the programmer. this makes valgrinding *really* annoying. some examples: program name XDG folders user information charset information g_random default generator gtester test suites i propose the addition of an API to gmem.h. something like g_mem_register_cleanup_func(). various bits of glib that allocate "permanent" memory would write functions to free that memory and register those functions here. then we would have a G_DEBUG flag for "gmem-cleanup" or something. in the case that that flag is not set, then the g_mem_register_cleanup_func() API does absolutely nothing. if the flag is set, then that API adds the cleanup functions to a linked list of cleanup functions to be called from a function in gmem.c that is setup as an atexit() handler.
Created attachment 153243 [details] [review] Bug 609281 - pedantic memory freeing Add g_mem_add_cleanup() function that registers functions to be run at program termination if G_DEBUG=gmem-cleanup is set.
three trivial issues: the comment /* atexit-free */ doesn't match the name of the flag and i missed adding to glib-sections.txt and the Since: tag. also: obviously in order for this to be useful it will need to be used from various glib modules. i'm holding off on that for now until i get some feedback.
Probably some potential to interact badly with programs that use atexit themselves. (Not that there's any good reason to use atexit.)
Now that we have ctors in glib, we should probably just do this with a dtor. That means that it would not be run until after anything that could possibly use glib has already quit (and well after atexit() handlers).
newer bug has more patches/discussion *** This bug has been marked as a duplicate of bug 627423 ***