After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 695129 - vfunc arguments are leaked: test_object_vfuncs
vfunc arguments are leaked: test_object_vfuncs
Product: pygobject
Classification: Bindings
Component: introspection
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks: 693111
Reported: 2013-03-04 15:27 UTC by Martin Pitt
Modified: 2018-01-10 20:23 UTC
See Also:
GNOME target: ---
GNOME version: ---

Description Martin Pitt 2013-03-04 15:27:17 UTC
The test_gi.TestPythonGObject.test_callback_in_vfunc test case leaks its string return values:

==24737== 6 bytes in 1 blocks are definitely lost in loss record 14 of 4,791
==24737==    at 0x4C2CD7B: malloc (in /usr/lib/valgrind/
==24737==    by 0xAC737AF: standard_malloc (gmem.c:85)
==24737==    by 0xAC73838: g_malloc (gmem.c:159)
==24737==    by 0xAC73B3E: g_malloc_n (gmem.c:400)
==24737==    by 0xAC8EE21: g_strdup (gstrfuncs.c:364)
==24737==    by 0xA539136: _pygi_argument_from_object (pygi-argument.c:1098)
==24737==    by 0xA540D23: _pygi_closure_assign_pyobj_to_retval (pygi-closure.c:35)
==24737==    by 0xA5426C6: _pygi_closure_set_out_arguments (pygi-closure.c:409)
==24737==    by 0xA542D23: _pygi_closure_handle (pygi-closure.c:505)
==24737==    by 0xB7229F6: ffi_closure_unix64_inner (in /usr/lib/x86_64-linux-gnu/
==24737==    by 0xB722D7F: ffi_closure_unix64 (in /usr/lib/x86_64-linux-gnu/
==24737==    by 0xD5F8D15: gi_marshalling_tests_object_method_str_arg_out_ret (gimarshallingtests.c:4081)
==24737== LEAK SUMMARY:
==24737==    definitely lost: 6 bytes in 1 blocks
==24737==    indirectly lost: 0 bytes in 0 blocks

This is happening here:

            self.assertEqual(object_.method_str_arg_out_ret('hello'), ('HELLO', 5))
Comment 1 Martin Pitt 2013-03-04 15:29:10 UTC
Sorry, that was meant to be the test_gi.TestPythonGObject.test_object_vfuncs test case.
Comment 2 Simon Feltman 2014-09-11 19:37:31 UTC
Not sure this one is fixable since "arg" is marked as transfer-none. There is really no way we can return a string (or anything that needs memory management marked with transfer-none) from the Python implemented vfunc without leaking. The problem is if we don't copy the string, its pointer is not guaranteed to persist longer than our vfunc callback which is required by the callee of the vfunc.
Comment 3 Simon Feltman 2014-09-11 19:54:25 UTC
Here's an updated call stack:

$ make check.valgrind TEST_NAMES=test_gi.TestPythonGObject.test_object_vfuncs

==32225== 6 bytes in 1 blocks are definitely lost in loss record 279 of 35,019
==32225==    at 0x4C2745D: malloc (in /usr/lib64/valgrind/
==32225==    by 0xF9E7DE6: g_malloc (gmem.c:97)
==32225==    by 0xF9E80FD: g_malloc_n (gmem.c:332)
==32225==    by 0xFA03469: g_strdup (gstrfuncs.c:356)
==32225==    by 0xEB0CDD5: _pygi_marshal_from_py_utf8 (pygi-basictype.c:230)
==32225==    by 0xEB0D625: _pygi_marshal_from_py_basic_type (pygi-basictype.c:495)
==32225==    by 0xEB0D6A4: _pygi_marshal_from_py_basic_type_cache_adapter (pygi-basictype.c:518)
==32225==    by 0xEB06A14: _pygi_closure_set_out_arguments (pygi-closure.c:469)
==32225==    by 0xEB06E30: _pygi_closure_handle (pygi-closure.c:592)
==32225==    by 0xFCF2B7A: ffi_closure_unix64_inner (in /usr/lib64/
==32225==    by 0xFCF2EF3: ffi_closure_unix64 (in /usr/lib64/
==32225==    by 0x1135A11B: gi_marshalling_tests_object_method_str_arg_out_ret (gimarshallingtests.c:4121)
==32225==    by 0xFCF2D8B: ffi_call_unix64 (in /usr/lib64/
==32225==    by 0xFCF26BB: ffi_call (in /usr/lib64/
==32225==    by 0xEB0A5B3: pygi_invoke_c_callable (pygi-invoke.c:628)
==32225==    by 0xEB0B893: _function_cache_invoke_real (pygi-cache.c:714)
==32225==    by 0xEB0BA92: pygi_function_cache_invoke (pygi-cache.c:793)
==32225==    by 0xEB0A6B5: pygi_callable_info_invoke (pygi-invoke.c:671)
==32225==    by 0xEB0A7F9: _wrap_g_callable_info_invoke (pygi-invoke.c:708)
==32225==    by 0xEAF7715: _callable_info_call (pygi-info.c:557)

Note that there are multiple leaks with this test (the test is overly complex). This ticket is specifically refering to leaks related to the vfunc implementation and calling of GIMarshallingTests.Object.[do_]method_str_arg_out_ret()

This leak is conceptually similar to the workaround for GObject references here:

An option to get rid of this leak would be to annotate the argument as transfer-full.
Comment 4 GNOME Infrastructure Team 2018-01-10 20:23:32 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: