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 711744 - Implement GCleanup in libglib
Implement GCleanup in libglib
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 555014 (view as bug list)
Depends on: 711751 711753 711754 711755 711756 711775
Blocks: 627423
 
 
Reported: 2013-11-09 21:24 UTC by Stef Walter
Modified: 2018-05-24 15:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Make some use of G_CLEANUP_ADD (11.14 KB, patch)
2013-11-09 23:40 UTC, Stef Walter
none Details | Review
memcheck: Add a 'make memcheck' target that runs valgrind (3.03 KB, patch)
2013-11-09 23:40 UTC, Stef Walter
none Details | Review
gthread-posix: Don't use gslice allocated GRecMutex (1.26 KB, patch)
2013-11-09 23:41 UTC, Stef Walter
none Details | Review
GThread posix: add impl structs to cleanup list (6.78 KB, patch)
2013-11-09 23:46 UTC, Stef Walter
none Details | Review
gcleanup: Add in more gtestutils.c cleanups (885 bytes, patch)
2013-11-09 23:47 UTC, Stef Walter
none Details | Review
glib: Define cleanup lists for glib tests (1.82 KB, patch)
2013-11-09 23:50 UTC, Stef Walter
none Details | Review
gcleanup: Hookup up more libglib globals to cleanup (4.62 KB, patch)
2013-11-09 23:54 UTC, Stef Walter
none Details | Review
gmessages: Initialize GPrivate so it gets cleaned up (926 bytes, patch)
2013-11-09 23:57 UTC, Stef Walter
none Details | Review
642026: Run less locking iterations under valgrind (1.39 KB, patch)
2013-11-09 23:58 UTC, Stef Walter
none Details | Review
slice: Don't run GSlice tests under valgrind (1.66 KB, patch)
2013-11-10 00:01 UTC, Stef Walter
none Details | Review
threadpool-test: Cleanup memory in test (1020 bytes, patch)
2013-11-10 00:04 UTC, Stef Walter
none Details | Review
gthreadpool: Cleanup thread pool unused threads (2.53 KB, patch)
2013-11-10 00:06 UTC, Stef Walter
none Details | Review
gcleanup: Hook up more libglib globals to cleanup (4.84 KB, patch)
2013-11-10 10:03 UTC, Stef Walter
none Details | Review
gthreadpool: Cleanup thread pool unused threads (3.11 KB, patch)
2013-11-10 10:21 UTC, Stef Walter
none Details | Review
gthreadpool: Cleanup thread pool unused threads (3.48 KB, patch)
2013-11-10 13:35 UTC, Stef Walter
none Details | Review
gmessages: Initialize GPrivate so it gets cleaned up (1.09 KB, patch)
2013-12-10 17:34 UTC, Stef Walter
none Details | Review

Description Stef Walter 2013-11-09 21:24:04 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.
Comment 1 Stef Walter 2013-11-09 23:40:11 UTC
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>
Comment 2 Stef Walter 2013-11-09 23:40:42 UTC
Created attachment 259359 [details] [review]
memcheck: Add a 'make memcheck' target that runs valgrind

Checks for memory errors and leaks
Comment 3 Stef Walter 2013-11-09 23:41:06 UTC
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 4 Stef Walter 2013-11-09 23:41:57 UTC
Comment on attachment 259360 [details] [review]
gthread-posix: Don't use gslice allocated GRecMutex

Moving to own bug.
Comment 5 Stef Walter 2013-11-09 23:46:53 UTC
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>
Comment 6 Stef Walter 2013-11-09 23:47:28 UTC
Created attachment 259363 [details] [review]
gcleanup: Add in more gtestutils.c cleanups
Comment 7 Stef Walter 2013-11-09 23:50:44 UTC
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.
Comment 8 Stef Walter 2013-11-09 23:54:06 UTC
Created attachment 259368 [details] [review]
gcleanup: Hookup up more libglib globals to cleanup
Comment 9 Stef Walter 2013-11-09 23:57:12 UTC
Created attachment 259370 [details] [review]
gmessages: Initialize GPrivate so it gets cleaned up
Comment 10 Stef Walter 2013-11-09 23:58:22 UTC
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.
Comment 11 Stef Walter 2013-11-10 00:01:07 UTC
Created attachment 259379 [details] [review]
slice: Don't run GSlice tests under valgrind
Comment 12 Stef Walter 2013-11-10 00:04:01 UTC
Created attachment 259388 [details] [review]
threadpool-test: Cleanup memory in test
Comment 13 Stef Walter 2013-11-10 00:06:22 UTC
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
Comment 14 Stef Walter 2013-11-10 10:03:25 UTC
Created attachment 259409 [details] [review]
gcleanup: Hook up more libglib globals to cleanup
Comment 15 Stef Walter 2013-11-10 10:21:52 UTC
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
Comment 16 Stef Walter 2013-11-10 13:35:42 UTC
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
Comment 17 Matthias Clasen 2013-11-23 16:20:55 UTC
*** Bug 666114 has been marked as a duplicate of this bug. ***
Comment 18 Matthias Clasen 2013-11-23 20:18:44 UTC
*** Bug 555014 has been marked as a duplicate of this bug. ***
Comment 19 Matthias Clasen 2013-11-23 20:19:11 UTC
*** Bug 627423 has been marked as a duplicate of this bug. ***
Comment 20 Stef Walter 2013-12-10 17:34:06 UTC
Created attachment 263934 [details] [review]
gmessages: Initialize GPrivate so it gets cleaned up
Comment 21 GNOME Infrastructure Team 2018-05-24 15:51:56 UTC
-- 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.