GNOME Bugzilla – Bug 711744
Implement GCleanup in libglib
Last modified: 2018-05-24 15:51:56 UTC
Implement GCleanup in libglib and associated tests. I've split this out from bug #627423 for simplicity, since there are quite a few patches. That should make it easier to review, track dependencies and so on.
Created attachment 259358 [details] [review] Make some use of G_CLEANUP_ADD This is enough to get a few testcases running with zero memory in use at the end. Tweaked by: Stef Walter <stefw@redhat.com>
Created attachment 259359 [details] [review] memcheck: Add a 'make memcheck' target that runs valgrind Checks for memory errors and leaks
Created attachment 259360 [details] [review] gthread-posix: Don't use gslice allocated GRecMutex This leads to problems during cleanup, and seems strange to have locks defined in terms of things that need locking. https://bugzilla.gnome.org/show_bug.cgi?id=627423
Comment on attachment 259360 [details] [review] gthread-posix: Don't use gslice allocated GRecMutex Moving to own bug.
Created attachment 259362 [details] [review] GThread posix: add impl structs to cleanup list There are two ways of using the structs like GMutex, GCond, etc. The first is to explicitly _init() and _clear() them. This is when you use them as part of another structure. This case is not interesting for gcleanup. The other is to have them in static storage (zero-filled) and just use them for the first time. This is the difficult case, because we don't ever free the impl in that case. In the first case, the impl is created and set in the _init() function. We can therfore tell that we are in the second case if we get to the get_impl() function and the impl is not there yet. In that case, add it to the cleanup list. There are probably people that allocate a GMutex as part of a zero-filled structure and use it, then call g_mutex_clear() on it. This is technically a violation of the API and these users will crash with G_DEBUG=cleanup, but that's a good thing because it will cause them to fix their code. All threading primitives are cleaned up on the graveyard shift, so that they can be used by other cleanup functions is libglib. Because GPrivate has a callback, and we need to run that callback for the main thread, we schedule two cleanups for it. The cleanup needs to run in the cleanup scope where the GPrivate callback is defined, so adapt G_PRIVATE_INIT to do this. Tweaked by: Stef Walter <stefw@redhat.com>
Created attachment 259363 [details] [review] gcleanup: Add in more gtestutils.c cleanups
Created attachment 259365 [details] [review] glib: Define cleanup lists for glib tests This allows G_CLEANUP to be used in the tests, and from things like G_PRIVATE_INIT and so on.
Created attachment 259368 [details] [review] gcleanup: Hookup up more libglib globals to cleanup
Created attachment 259370 [details] [review] gmessages: Initialize GPrivate so it gets cleaned up
Created attachment 259372 [details] [review] 642026: Run less locking iterations under valgrind Otherwise these tests are prohibitively slow. Under valgrind the same race conditions aren't likely to show up anyway.
Created attachment 259379 [details] [review] slice: Don't run GSlice tests under valgrind
Created attachment 259388 [details] [review] threadpool-test: Cleanup memory in test
Created attachment 259390 [details] [review] gthreadpool: Cleanup thread pool unused threads This requires different phases getting involved: * early: Signal all the unused pool threads, and change unused limits to zero, so no new unused pool threads. * default: Join all unused pool threads. * late: Free up the unused thread queue
Created attachment 259409 [details] [review] gcleanup: Hook up more libglib globals to cleanup
Created attachment 259412 [details] [review] gthreadpool: Cleanup thread pool unused threads This requires different phases getting involved: * early: Signal all the unused pool threads, and change unused limits to zero, so no new unused pool threads. * default: Join all unused pool threads. * late: Free up the unused thread queue
Created attachment 259418 [details] [review] gthreadpool: Cleanup thread pool unused threads This requires different phases getting involved: * early: Signal all the unused pool threads, and change unused limits to zero, so no new unused pool threads. * default: Join all unused pool threads. * late: Free up the unused thread queue
*** Bug 666114 has been marked as a duplicate of this bug. ***
*** Bug 555014 has been marked as a duplicate of this bug. ***
*** Bug 627423 has been marked as a duplicate of this bug. ***
Created attachment 263934 [details] [review] gmessages: Initialize GPrivate so it gets cleaned up
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/778.