Commit 64bcca2d authored by Martin Pitt's avatar Martin Pitt
Browse files

Fix memory handling of caller-allocated boxed types

_pygi_marshal_to_py_interface_struct() and other places treat subtypes of
G_TYPE_BOXED as boxed values and wrap them with _pygi_boxed_new(). Fix
_caller_alloc() and _cleanup_caller_allocates() to consider G_TYPE_BOXED
subtypes as well and use the slice allocator instead of malloc()'ing a struct.
This avoids trying to free an malloc'ed struct with g_slice_free() and properly
cleans up the boxed values.

The leak was produced with:

G_SLICE=debug-blocks PYTHONPATH=. valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no \
  python3 -c 'from gi.repository import Gtk; b=Gtk.TextBuffer(); (s,e) = b.get_bounds()'
parent 4f5e8b75
......@@ -366,7 +366,7 @@ static gboolean _caller_alloc (PyGIInvokeState *state,
state->out_args[out_count].v_pointer = NULL;
state->args[arg_count] = &state->out_args[out_count];
if (iface_cache->g_type == G_TYPE_BOXED) {
if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
state->args[arg_count]->v_pointer =
_pygi_boxed_alloc (iface_cache->interface_info, NULL);
} else if (iface_cache->g_type == G_TYPE_VALUE) {
......@@ -29,7 +29,7 @@ _cleanup_caller_allocates (PyGIInvokeState *state,
PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)cache;
if (iface_cache->g_type == G_TYPE_BOXED) {
if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) {
gsize size;
if (was_processed)
return; /* will be cleaned up at deallocation */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment