[pygobject] Correct a bug in the freeing of memory in pygi-invoke.c.



commit 8c2d32c8205b971b4353e3d5d2ed1efa6ef0e06c
Author: Damien Caliste <damien caliste cea fr>
Date:   Fri Nov 12 10:20:32 2010 +0100

    Correct a bug in the freeing of memory in pygi-invoke.c.
    
    When a method with inout arguments is called from Python with
    a wrong number of arguments, the system crashs because of an
    assertion fail. This patch corrects this behaviour.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=634671

 gi/pygi-invoke.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 71d5859..3a4fafa 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -846,9 +846,7 @@ _free_invocation_state (struct invocation_state *state)
             continue;
         }
 
-        if (state->args != NULL
-            && state->args[i] != NULL
-            && state->arg_infos[i] != NULL
+        if (state->arg_infos[i] != NULL
             && state->arg_type_infos[i] != NULL) {
             GIDirection direction;
             GITypeTag type_tag;
@@ -857,20 +855,25 @@ _free_invocation_state (struct invocation_state *state)
             direction = g_arg_info_get_direction (state->arg_infos[i]);
             transfer = g_arg_info_get_ownership_transfer (state->arg_infos[i]);
 
-            type_tag = g_type_info_get_tag (state->arg_type_infos[i]);
-
             /* Release the argument. */
             if (direction == GI_DIRECTION_INOUT) {
-                _pygi_argument_release (&state->backup_args[backup_args_pos], state->arg_type_infos[i],
-                                        transfer, GI_DIRECTION_IN);
+                if (state->args != NULL) {
+                    _pygi_argument_release (&state->backup_args[backup_args_pos],
+                                            state->arg_type_infos[i],
+                                            transfer, GI_DIRECTION_IN);
+                }
                 backup_args_pos += 1;
             }
-           _pygi_argument_release (state->args[i], state->arg_type_infos[i], transfer, direction);
+            if (state->args != NULL && state->args[i] != NULL) {
+                _pygi_argument_release (state->args[i], state->arg_type_infos[i],
+                                        transfer, direction);
 
-            if (type_tag == GI_TYPE_TAG_ARRAY
+                type_tag = g_type_info_get_tag (state->arg_type_infos[i]);
+                if (type_tag == GI_TYPE_TAG_ARRAY
                     && (direction != GI_DIRECTION_IN && transfer == GI_TRANSFER_NOTHING)) {
-                /* We created a #GArray and it has not been released above, so free it. */
-                state->args[i]->v_pointer = g_array_free (state->args[i]->v_pointer, FALSE);
+                    /* We created a #GArray and it has not been released above, so free it. */
+                    state->args[i]->v_pointer = g_array_free (state->args[i]->v_pointer, FALSE);
+                }
             }
 
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]