[pygobject] Fix leaking inout C arrays
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix leaking inout C arrays
- Date: Mon, 4 Mar 2013 09:25:01 +0000 (UTC)
commit d32b410a1b1fcca6d10d75fbd771ea789999da64
Author: Martin Pitt <martinpitt gnome org>
Date: Mon Mar 4 10:19:34 2013 +0100
Fix leaking inout C arrays
g_*_info_invoke() changes the original state->in_args and state->args C arrays
to the output values for (inout) arguments, thus losing the pointer to the
originally allocated array. Remember that in state->args_data, so that we can
free it in _pygi_marshal_cleanup_from_py_array().
Reproduced by test_gi.TestArray.test_array_fixed_inout test case.
gi/pygi-marshal-cleanup.c | 6 ++++++
gi/pygi-marshal-from-py.c | 4 ++++
2 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index 77fbf08..d7d1b63 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -101,6 +101,12 @@ pygi_marshal_cleanup_args_from_py_marshal_success (PyGIInvokeState *state,
arg_cache->direction == PYGI_DIRECTION_FROM_PYTHON &&
state->args[i]->v_pointer != NULL)
cleanup_func (state, arg_cache, state->args[i]->v_pointer, TRUE);
+
+ if (cleanup_func &&
+ arg_cache->direction == PYGI_DIRECTION_BIDIRECTIONAL &&
+ state->args_data[i] != NULL) {
+ cleanup_func (state, arg_cache, state->args_data[i], TRUE);
+ }
}
}
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 570b464..9f46977 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -1104,6 +1104,10 @@ array_success:
if (sequence_cache->array_type == GI_ARRAY_TYPE_C) {
arg->v_pointer = array_->data;
g_array_free (array_, FALSE);
+ /* remember the originally allocated array in args_data, as args and
+ * in_args get changed for (inout) arguments */
+ if (arg_cache->transfer == GI_TRANSFER_NOTHING)
+ state->args_data[arg_cache->c_arg_index] = arg->v_pointer;
} else {
arg->v_pointer = array_;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]