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 682560 - leak fixes
leak fixes
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-08-23 17:36 UTC by Dan Winship
Modified: 2013-02-03 05:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gmain: free source_lists when freeing GMainContext (1.23 KB, patch)
2012-08-23 17:36 UTC, Dan Winship
committed Details | Review
gmain: don't leak child sources that are destroyed before their parents (3.29 KB, patch)
2012-08-23 17:36 UTC, Dan Winship
committed Details | Review
gmain: remove unix signal watch if its GSourceFunc returns FALSE (1.03 KB, patch)
2012-08-23 17:36 UTC, Dan Winship
committed Details | Review
g_option_context_help: don't modify the input data (6.06 KB, patch)
2012-08-23 17:37 UTC, Dan Winship
committed Details | Review
gtestutils: add g_test_add_data_func_full() (3.45 KB, patch)
2012-08-23 17:37 UTC, Dan Winship
committed Details | Review
glib/tests: fix leaks (92.19 KB, patch)
2012-08-23 17:37 UTC, Dan Winship
committed Details | Review
gobject/tests: use g_test_expect_messages() (2.93 KB, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review
gobject/tests: plug leaks (1.91 KB, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review
xdgmime: plug a small leak (652 bytes, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review
GDesktopAppInfo: fix leaks (1.22 KB, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review
g_file_copy: plug a leak (893 bytes, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review
gio/tests: port some stuff to g_test_expect_message() (10.07 KB, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review
gio/tests/cancellable: fix to still work when running slowly (1.81 KB, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review
gio/tests: fix leaks (19.21 KB, patch)
2012-08-27 11:49 UTC, Dan Winship
committed Details | Review

Description Dan Winship 2012-08-23 17:36:51 UTC
Was looking at trying to land bug 666114 and ended up doing some
leakfixing.

You can argue whether the unix signal watch patch is (a) an API change
that may break existing code, or (b) a fix to an obvious bug that no
one ever reported... I went for (b). If other people think (a) then we
can just change the documentation (and the test program) instead.

The patch to glib/tests/regex.c is huge just because I got anal about
re-aligning all the "\"s. The only real change is the switch to use
g_test_add_data_func_full().
Comment 1 Dan Winship 2012-08-23 17:36:53 UTC
Created attachment 222245 [details] [review]
gmain: free source_lists when freeing GMainContext

If a context was freed with sources still attached, those sources
correctly got destroyed, but the corresponding GSourceList structs
were being leaked.
Comment 2 Dan Winship 2012-08-23 17:36:56 UTC
Created attachment 222246 [details] [review]
gmain: don't leak child sources that are destroyed before their parents

A parent source holds refs on its children, so if the child source is
destroyed, we need to drop that ref. Fix, and reorganize to make this
all more obvious.
Comment 3 Dan Winship 2012-08-23 17:36:58 UTC
Created attachment 222247 [details] [review]
gmain: remove unix signal watch if its GSourceFunc returns FALSE

g_unix_signal_watch_dispatch() was ignore the callback's return value.
Fix that.
Comment 4 Dan Winship 2012-08-23 17:37:00 UTC
Created attachment 222248 [details] [review]
g_option_context_help: don't modify the input data

If there are options that need their names to be aliased, keep track
of that internally rather than modifying the passed-in GOptionGroup
(and leaking strings in the process).
Comment 5 Dan Winship 2012-08-23 17:37:03 UTC
Created attachment 222249 [details] [review]
gtestutils: add g_test_add_data_func_full()

Like g_test_add_data_func(), but includes a GDestroyNotify for the
test data.
Comment 6 Dan Winship 2012-08-23 17:37:06 UTC
Created attachment 222250 [details] [review]
glib/tests: fix leaks
Comment 7 Colin Walters 2012-08-24 01:21:06 UTC
Review of attachment 222245 [details] [review]:

This is a regression introduced by 55bac5da0ada8f46824a4d565cdd8ea7e3774a47 right?

Hm.  How is freeing a context with sources still attached possible?  I'd have thought the source would hold a ref on the context.  But looking at the code, that's not the case.  Ah, I see.  Ok.
Comment 8 Colin Walters 2012-08-24 01:32:25 UTC
Review of attachment 222246 [details] [review]:

I think this makes sense...
Comment 9 Colin Walters 2012-08-24 01:32:43 UTC
Review of attachment 222247 [details] [review]:

Per IRC discussion, this looks safe.
Comment 10 Colin Walters 2012-08-24 01:34:52 UTC
Review of attachment 222248 [details] [review]:

This is a pretty old leak...it dates to:

commit 2effb8d0eaf8041615dda14e4cc82ed764255859
Author: Matthias Clasen <mclasen@redhat.com>
Date:   Fri Sep 3 21:20:07 2010 -0400

    Remove excessive header includes


Which seems to have nothing to do with headers...I'm leaving this one for Matthias to look at.
Comment 11 Colin Walters 2012-08-24 01:35:45 UTC
Review of attachment 222249 [details] [review]:

A new test API, but no tests using it?
Comment 12 Colin Walters 2012-08-24 01:37:19 UTC
Review of attachment 222249 [details] [review]:

Nevermind, I see that's in the next patch.
Comment 13 Colin Walters 2012-08-24 01:41:05 UTC
Review of attachment 222250 [details] [review]:

All looks right to me.
Comment 14 Matthias Clasen 2012-08-25 00:49:45 UTC
Review of attachment 222248 [details] [review]:

Looks right, though it took a while to spot the actual leak among all the changes. Might be nicer to do this as two changes:
- first plug the leak (by freeing the old entry->long_name before overwriting it)
- then introduce the aliases hash table to avoid modifying the entry
Comment 15 Dan Winship 2012-08-25 01:08:37 UTC
(In reply to comment #14)
> Might be nicer to do this as two changes:
> - first plug the leak (by freeing the old entry->long_name before overwriting
> it)
> - then introduce the aliases hash table to avoid modifying the entry

No, the leaked memory is the *new* entry->long_name value; the old value is (almost certainly) a compile-time constant. So to avoid leaking, we have to free the new value before we return, meaning we need some data structure to keep track of all the new strings we created. And then, if we want the entry to still be valid when we return, then it has to still/again have the old long_name value when we return, since the new value will have been freed. So there's no way to split this into two pieces.
Comment 16 Dan Winship 2012-08-27 11:49:25 UTC
Created attachment 222529 [details] [review]
gobject/tests: use g_test_expect_messages()
Comment 17 Dan Winship 2012-08-27 11:49:28 UTC
Created attachment 222530 [details] [review]
gobject/tests: plug leaks
Comment 18 Dan Winship 2012-08-27 11:49:30 UTC
Created attachment 222531 [details] [review]
xdgmime: plug a small leak
Comment 19 Dan Winship 2012-08-27 11:49:32 UTC
Created attachment 222532 [details] [review]
GDesktopAppInfo: fix leaks

g_desktop_app_info_ensure_saved() was leaking the file contents.

_g_desktop_app_info_launch_uris_internal() was leaking the session bus
on error.
Comment 20 Dan Winship 2012-08-27 11:49:35 UTC
Created attachment 222533 [details] [review]
g_file_copy: plug a leak

The fallback copy code was leaking the GFileInfo if it didn't have
G_FILE_ATTRIBUTE_STANDARD_TYPE.
Comment 21 Dan Winship 2012-08-27 11:49:37 UTC
Created attachment 222534 [details] [review]
gio/tests: port some stuff to g_test_expect_message()
Comment 22 Dan Winship 2012-08-27 11:49:40 UTC
Created attachment 222535 [details] [review]
gio/tests/cancellable: fix to still work when running slowly

The test was assuming that all cancelled ops would finish within a
certain amount of time, but this often failed under valgrind. Instead,
just run the loop until all of the ops have actually finished.
Comment 23 Dan Winship 2012-08-27 11:49:43 UTC
Created attachment 222536 [details] [review]
gio/tests: fix leaks
Comment 24 Matthias Clasen 2012-09-01 15:30:48 UTC
Review of attachment 222529 [details] [review]:

ok
Comment 25 Matthias Clasen 2012-09-01 15:30:59 UTC
Review of attachment 222529 [details] [review]:

ok
Comment 26 Matthias Clasen 2012-09-01 15:31:31 UTC
Review of attachment 222530 [details] [review]:

ok
Comment 27 Matthias Clasen 2012-09-01 15:33:09 UTC
Review of attachment 222530 [details] [review]:

ok
Comment 28 Matthias Clasen 2012-09-01 15:33:18 UTC
Review of attachment 222530 [details] [review]:

ok
Comment 29 Matthias Clasen 2012-09-01 15:33:46 UTC
Review of attachment 222531 [details] [review]:

ok
Comment 30 Matthias Clasen 2012-09-01 15:34:13 UTC
Review of attachment 222532 [details] [review]:

ok
Comment 31 Matthias Clasen 2012-09-01 15:34:41 UTC
Review of attachment 222533 [details] [review]:

ok
Comment 32 Matthias Clasen 2012-09-01 15:35:33 UTC
Review of attachment 222534 [details] [review]:

sure
Comment 33 Matthias Clasen 2012-09-01 15:37:00 UTC
Review of attachment 222535 [details] [review]:

sure
Comment 34 Matthias Clasen 2012-09-01 15:37:49 UTC
Review of attachment 222536 [details] [review]:

ok
Comment 35 Dan Winship 2012-09-03 12:56:44 UTC
Attachment 222529 [details] pushed as e0cba35 - gobject/tests: use g_test_expect_messages()
Attachment 222530 [details] pushed as 03be681 - gobject/tests: plug leaks
Attachment 222531 [details] pushed as 4e7031f - xdgmime: plug a small leak
Attachment 222532 [details] pushed as fa58cef - GDesktopAppInfo: fix leaks
Attachment 222533 [details] pushed as 039ecf2 - g_file_copy: plug a leak
Attachment 222534 [details] pushed as 568f737 - gio/tests: port some stuff to g_test_expect_message()
Attachment 222535 [details] pushed as 17bb9d5 - gio/tests/cancellable: fix to still work when running slowly
Attachment 222536 [details] pushed as beb0f9c - gio/tests: fix leaks
Comment 36 Dan Winship 2012-09-03 12:58:26 UTC
g_option_context_help() patch still uncommitted (comment 4, comment 14, comment 15).
Comment 37 Christophe Fergeau 2012-09-03 13:46:48 UTC
(In reply to comment #35)
> Attachment 222531 [details] pushed as 4e7031f - xdgmime: plug a small leak

This one causes a double-free during gnome boxes startup, reverting it gets things back in order. xdg_dir_time_list_add takes ownership of file_name, I guess it's sometimes freeing it on its own.
Comment 38 Guillaume Desmottes 2012-09-03 14:05:57 UTC
I reported the regression as bug #683270
Comment 39 Matthias Clasen 2013-02-03 05:45:49 UTC
Review of attachment 222248 [details] [review]:

.
Comment 40 Matthias Clasen 2013-02-03 05:46:41 UTC
Attachment 222248 [details] pushed as 39a528b - g_option_context_help: don't modify the input data