[pygobject] Fix memory handling of caller-allocated boxed types
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix memory handling of caller-allocated boxed types
- Date: Thu, 28 Feb 2013 09:56:30 +0000 (UTC)
commit 64bcca2d39fed1734ad1abbe291406387e901f5c
Author: Martin Pitt <martinpitt gnome org>
Date: Thu Feb 28 10:48:18 2013 +0100
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()'
gi/pygi-invoke.c | 2 +-
gi/pygi-marshal-cleanup.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 96ffde3..0cbb9ca 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -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) {
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index 50f593d..77fbf08 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]