GNOME Bugzilla – Bug 587369
GValue handling shouldn't use the slice allocator
Last modified: 2009-08-01 01:19:57 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.
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.
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)?
Created attachment 137599 [details] [review] Use g_boxed methods for GValue copying/freeing Alternate version using g_boxed methods
This patch was breaking make check because you are not initializing the GValue. I fixed this and pushed. Thanks!