[pygi] Force out arguments to be initialized as NULL. Comes with a test.



commit 8240320d0b67074ce91bdf7aadcf5951c5a8c45a
Author: Zach Goldberg <zach zachgoldberg com>
Date:   Tue Apr 20 23:53:57 2010 -0400

    Force out arguments to be initialized as NULL.  Comes with a test.
    
    This fix was motivated by a real world library which had a transfer full
    utf8 out argument which sometimes was not set.  We would leave the pointer
    dangling and try and free it at the end of invoke() and crash.  Library refused
    to change their behavior so we're forced to take care of it on our end.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=616043

 gi/pygi-info.c   |    1 +
 tests/test_gi.py |    3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index 4f30fbf..3aa6dda 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -758,6 +758,7 @@ _wrap_g_function_info_invoke (PyGIBaseInfo *self,
                 case GI_DIRECTION_OUT:
                     g_assert(out_args_pos < n_out_args);
                     out_args[out_args_pos].v_pointer = &out_values[out_args_pos];
+                    out_values[out_args_pos].v_pointer = NULL;
                     args[i] = &out_values[out_args_pos];
                     out_args_pos += 1;
             }
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 7cab5db..d630398 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -646,6 +646,9 @@ class TestUtf8(unittest.TestCase):
     def test_utf8_full_out(self):
         self.assertEquals(CONSTANT_UTF8, GIMarshallingTests.utf8_full_out())
 
+    def test_utf8_dangling_out(self):
+        GIMarshallingTests.utf8_dangling_out()
+
     def test_utf8_none_inout(self):
         self.assertEquals("", GIMarshallingTests.utf8_none_inout(CONSTANT_UTF8))
 



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