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 652954 - Plug leak in closure destruction
Plug leak in closure destruction
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2011-06-19 18:02 UTC by Giovanni Campagna
Modified: 2011-06-20 20:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Function: plug a memory leak (979 bytes, patch)
2011-06-19 18:03 UTC, Giovanni Campagna
reviewed Details | Review
Update suppression file (2.85 KB, patch)
2011-06-19 18:04 UTC, Giovanni Campagna
reviewed Details | Review
Update suppression file (2.18 KB, patch)
2011-06-20 17:01 UTC, Giovanni Campagna
committed Details | Review
Free allocated ffi_types in g_callable_info_free_closure() (887 bytes, patch)
2011-06-20 19:20 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2011-06-19 18:02:53 UTC
Apparently, g_callable_free_closure does not free all the resources allocated by g_callable_info_prepare_closure. In particular, it does not free the data inside ffi_cif.
Patch coming.
Comment 1 Giovanni Campagna 2011-06-19 18:03:18 UTC
Created attachment 190214 [details] [review]
Function: plug a memory leak

g_callable_info_prepare_closure() allocates memory for the argument
types stored in the ffi_cif, so we need to free it.
Comment 2 Giovanni Campagna 2011-06-19 18:04:00 UTC
Created attachment 190215 [details] [review]
Update suppression file

For better valgrind results

With this, valgrinding gjs-unit -p /js/EverythingBasic shows no errors.
Comment 3 Colin Walters 2011-06-20 14:18:58 UTC
Review of attachment 190215 [details] [review]:

::: test/gjs.supp
@@ +30,3 @@
+   Memcheck:Leak
+   ...
+   fun:g_slice_alloc

You should always run valgrind with G_SLICE=always-malloc in the environment; make valgrind-check already does this.
Comment 4 Colin Walters 2011-06-20 14:43:51 UTC
Review of attachment 190214 [details] [review]:

This one confuses me; I don't see g_callable_info_prepare_closure() g_malloc()ing anything.  Note the "ffi_cif cif" structure is embedded in the GjsCallbackTrampoline structure.
Comment 5 Giovanni Campagna 2011-06-20 16:25:29 UTC
(In reply to comment #4)
> Review of attachment 190214 [details] [review]:
> 
> This one confuses me; I don't see g_callable_info_prepare_closure()
> g_malloc()ing anything.  Note the "ffi_cif cif" structure is embedded in the
> GjsCallbackTrampoline structure.

g_callable_info_get_ffi_arg_types() allocates an array of ffi_types*, and ffi_prep_cif() embeds it into ffi_cif
Comment 6 Giovanni Campagna 2011-06-20 17:01:31 UTC
Created attachment 190293 [details] [review]
Update suppression file

For better valgrind results
Comment 7 Colin Walters 2011-06-20 17:46:19 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > Review of attachment 190214 [details] [review] [details]:
> > 
> > This one confuses me; I don't see g_callable_info_prepare_closure()
> > g_malloc()ing anything.  Note the "ffi_cif cif" structure is embedded in the
> > GjsCallbackTrampoline structure.
> 
> g_callable_info_get_ffi_arg_types() allocates an array of ffi_types*, and
> ffi_prep_cif() embeds it into ffi_cif

Ah, you're right.  But then the bug is in gobject-introspection; we should free the types inside g_callable_info_free_closure().
Comment 8 Colin Walters 2011-06-20 18:35:57 UTC
Review of attachment 190293 [details] [review]:

Looks OK.  Sort of unfortunate about the fontconfig/gettext stuff; maybe it'd be worth trying to get a "standard" glib suppression file that's actually maintained, but whatever.  Let's commit this for now and move on =)
Comment 9 Colin Walters 2011-06-20 19:13:11 UTC
Comment on attachment 190293 [details] [review]
Update suppression file

Attachment 190293 [details] pushed as 8eb3716 - Update suppression file
Comment 10 Giovanni Campagna 2011-06-20 19:20:21 UTC
Created attachment 190311 [details] [review]
Free allocated ffi_types in g_callable_info_free_closure()

g_callable_info_prepare_closure() allocates memory for the argument
types in the ffi_cif, so we need to free it.

The same fix, this time in gobject-introspection. Probably we need
to warn pygobject devs if this is merged.
Comment 11 Colin Walters 2011-06-20 19:23:44 UTC
Review of attachment 190311 [details] [review]:

Looks good.

I don't see pygobject freeing the args offhand.
Comment 12 Giovanni Campagna 2011-06-20 20:18:53 UTC
Attachment 190311 [details] pushed as 845ccc9 - Free allocated ffi_types in g_callable_info_free_closure()