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 587369 - GValue handling shouldn't use the slice allocator
GValue handling shouldn't use the slice allocator
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2009-06-29 21:43 UTC by Dan Winship
Modified: 2009-08-01 01:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GValues should be copied with g_malloc/g_free, not the slice allocator (1.41 KB, patch)
2009-06-29 21:44 UTC, Dan Winship
none Details | Review
Use g_boxed methods for GValue copying/freeing (1.99 KB, patch)
2009-06-30 02:09 UTC, Dan Winship
committed Details | Review

Description Dan Winship 2009-06-29 21:43:25 UTC
gi/arg.c uses g_slice_new() and g_slice_free() to manage GValues. However, GValue's boxed implementation uses g_new() and g_free(). While gjs is careful to never actually treat GValues as boxeds, this still causes problems.

In particular, if a method wants to return a GValue* (or GList* of GValue*, etc), then the code it uses it allocate the value must agree with the code gjs uses to free it (and more importantly, the code that every *other* binding is going to use to free it with as well). And since g_boxed_copy()/g_boxed_free() use g_malloc() and g_free() for GValues, then that seems like the right answer.
Comment 1 Dan Winship 2009-06-29 21:44:32 UTC
Created attachment 137588 [details] [review]
GValues should be copied with g_malloc/g_free, not the slice allocator

Fixes memory management of GValue* return values.
Comment 2 Johan Bilien 2009-06-29 22:02:23 UTC
Should we use something like that instead:

GValue v;

gjs_value_to_g_value(context, value, &v)
arg->v_pointer = g_boxed_copy(G_TYPE_VALUE, &v);


Then 
g_boxed_free(G_TYPE_VALUE, arg->v_pointer)?
Comment 3 Dan Winship 2009-06-30 02:09:33 UTC
Created attachment 137599 [details] [review]
Use g_boxed methods for GValue copying/freeing

Alternate version using g_boxed methods
Comment 4 Lucas Rocha 2009-08-01 01:19:57 UTC
This patch was breaking make check because you are not initializing the GValue. I fixed this and pushed. Thanks!