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 674800 - gclosure: generic marshaller leaks return value
gclosure: generic marshaller leaks return value
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 679829 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-04-25 15:03 UTC by Mark Nauwelaerts
Modified: 2012-08-05 12:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gclosure: generic marshaller should not copy and leak return value (1.72 KB, patch)
2012-04-25 15:03 UTC, Mark Nauwelaerts
reviewed Details | Review
tests: make refcount signals test slightly valgrind cleaner (702 bytes, patch)
2012-07-19 14:42 UTC, Mark Nauwelaerts
committed Details | Review
tests: add check for leaking signal return value (3.34 KB, patch)
2012-07-19 14:45 UTC, Mark Nauwelaerts
committed Details | Review
gclosure: generic marshaller should not copy and leak return value (1.88 KB, patch)
2012-07-23 09:20 UTC, Mark Nauwelaerts
committed Details | Review

Description Mark Nauwelaerts 2012-04-25 15:03:06 UTC
Created attachment 212788 [details] [review]
gclosure: generic marshaller should not copy and leak return value

Conversion from ffi type to GValue always uses g_value_set_... which in some cases (e.g. g_value_set_string) leaks the real returned value (from the callback) only to return a copy.

Attached patch replaces some _set_ by _take_ (only not sure about variant case, but looks like the _set_ should be ok).
Comment 1 Matej Knopp 2012-07-13 00:32:39 UTC
*** Bug 679829 has been marked as a duplicate of this bug. ***
Comment 2 Matthias Clasen 2012-07-14 12:26:35 UTC
do you have a testcase that demonstrates this leak when run under valgrind ?
Comment 3 Mark Nauwelaerts 2012-07-19 14:42:29 UTC
Created attachment 219233 [details] [review]
tests: make refcount signals test slightly valgrind cleaner
Comment 4 Mark Nauwelaerts 2012-07-19 14:45:04 UTC
Created attachment 219235 [details] [review]
tests: add check for leaking signal return value

Not sure what scope you have in mind with a 'test case', but this patch modifies one of the glib tests to include a signal with a string return value, which will shown as leaked by valgrind (among other cases as can be seen from the original patch).

The previous patch establishes a 'slightly cleaner valgrind baseline'.
Comment 5 Colin Walters 2012-07-19 17:03:30 UTC
Review of attachment 212788 [details] [review]:

Interesting; I guess signals returning allocated memory are sufficiently rare in the GTK+/GNOME stack that we didn't notice this before.  I certainly don't see any in GIO.

::: gobject/gclosure.c
@@ +1274,3 @@
       break;
     case G_TYPE_VARIANT:
       g_value_set_variant (gvalue, *(gpointer*)value);

Don't we need to change this to g_value_take_variant() too ?
Comment 6 Colin Walters 2012-07-19 17:04:21 UTC
Review of attachment 219233 [details] [review]:

Looks correct.
Comment 7 Colin Walters 2012-07-19 17:06:28 UTC
Review of attachment 219235 [details] [review]:

Note that tests/ directory is stuff that predates gtestutils.h.  So it's preferable to add new gobject tests to gobject/tests/, if there were an appropriate test there already.
Comment 8 Mark Nauwelaerts 2012-07-23 09:16:24 UTC
(In reply to comment #5)
> Review of attachment 212788 [details] [review]:
> 
> Interesting; I guess signals returning allocated memory are sufficiently rare
> in the GTK+/GNOME stack that we didn't notice this before.  I certainly don't
> see any in GIO.
> 
> ::: gobject/gclosure.c
> @@ +1274,3 @@
>        break;
>      case G_TYPE_VARIANT:
>        g_value_set_variant (gvalue, *(gpointer*)value);
> 
> Don't we need to change this to g_value_take_variant() too ?

Was not sure about the 'floating' here (with variant), but contrary to the original comment, it probably needs changing to g_value_take_variant().
Comment 9 Mark Nauwelaerts 2012-07-23 09:20:33 UTC
Created attachment 219469 [details] [review]
gclosure: generic marshaller should not copy and leak return value

Patch as before, but now also with g_value_take_variant()
Comment 10 Colin Walters 2012-07-26 14:43:08 UTC
Review of attachment 219469 [details] [review]:

OK.
Comment 11 Tim-Philipp Müller 2012-08-04 22:37:13 UTC
Mark, do you have developer access to git.gnome.org ?

It would be good to get this in as soon as possible.
Comment 12 Mark Nauwelaerts 2012-08-05 09:06:54 UTC
Only have gnome bugzilla account, but no gnome developer account.
Comment 13 Tim-Philipp Müller 2012-08-05 12:40:55 UTC
Took the liberty to push this to master and 2.32 branch then:


commit 10fc00b38515bc322d5e497d61a50165b04c3c8d
Author: Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Date:   Wed Apr 25 14:21:06 2012 +0200

    gclosure: do not copy and leak when generically marshalling return value
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674800

commit 24b9f61ee4b8b7bc755b84398207112c18b4121f
Author: Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Date:   Thu Jul 19 16:38:59 2012 +0200

    tests: add check for leaking signal return value
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674800

commit 13a1154b4cf664e486df9fa6a76d279b8090c49e
Author: Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Date:   Thu Jul 19 16:38:06 2012 +0200

    tests: make refcount signals test slightly valgrind cleaner


make check still passes on both branches and leak fix was confirmed via valgrind on the new test.