diff --git a/gi/pygi-info.c b/gi/pygi-info.c index dc34090b158d453b1d908daaec503009cd14d8c6..e378a75365aa8d031903ef70e779946524fc77c8 100644 --- a/gi/pygi-info.c +++ b/gi/pygi-info.c @@ -1897,7 +1897,8 @@ field_array_length (GIFieldInfo *info, void *struct_data_ptr, gi_base_info_unref (type_info); - container_info = gi_base_info_get_container ((GIBaseInfo *)info); + container_info = + gi_base_info_get_container ((GIBaseInfo *)info); /* borrowed! */ if (GI_IS_UNION_INFO (container_info)) { array_len_field = gi_union_info_get_field ( @@ -1912,7 +1913,6 @@ field_array_length (GIFieldInfo *info, void *struct_data_ptr, /* Other types don't have fields. */ g_assert_not_reached (); } - gi_base_info_unref (container_info); if (array_len_field == NULL) { return FALSE; diff --git a/tests/test_fields.py b/tests/test_fields.py index 3236486acc8c113206d94b25d7f822dda978455a..d83dbdceb1b756ddb1e3a98944c08755e50f1583 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,9 +1,7 @@ import math import unittest -from gi.repository import GLib -from gi.repository import Regress -from gi.repository import GIMarshallingTests +from gi.repository import GIMarshallingTests, GLib, Regress class Number: @@ -177,3 +175,13 @@ class TestFields(unittest.TestCase): def test_ghashtable(self): obj = Regress.TestObj() self.assertTrue(obj.hash_table is None) + + def test_array_field_with_length_annotation(self): + """Regression test for + Every time an array field was accessed, the reference count of the struct info would be decreased. + This was only the case for array fields with a length annotation. + """ + ITERATIONS = 100 # mostly arbitrarily chosen, but should be high enough to drop the reference count to zero. + obj = Regress.AnnotationFields() + for _ in range(0, ITERATIONS): + obj.arr