After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 609281 - pedantic memory freeing
pedantic memory freeing
Status: RESOLVED DUPLICATE of bug 627423
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-02-08 02:04 UTC by Allison Karlitskaya (desrt)
Modified: 2012-08-26 14:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Bug 609281 - pedantic memory freeing (3.95 KB, patch)
2010-02-08 02:56 UTC, Allison Karlitskaya (desrt)
none Details | Review

Description Allison Karlitskaya (desrt) 2010-02-08 02:04:10 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.
Comment 1 Allison Karlitskaya (desrt) 2010-02-08 02:56:49 UTC
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.
Comment 2 Allison Karlitskaya (desrt) 2010-02-08 02:58:59 UTC
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.
Comment 3 Owen Taylor 2010-02-08 14:20:05 UTC
Probably some potential to interact badly with programs that use atexit themselves. (Not that there's any good reason to use atexit.)
Comment 4 Allison Karlitskaya (desrt) 2012-08-17 03:00:35 UTC
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).
Comment 5 Dan Winship 2012-08-26 14:54:26 UTC
newer bug has more patches/discussion

*** This bug has been marked as a duplicate of bug 627423 ***