From 4141eea25739bed16c553a4304d41c43f9165939 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 10 Apr 2024 00:20:24 +0100 Subject: [PATCH] girffi: Add hints to indicate ownership transfer into ffi_cif MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scan-build thinks that the `atypes` array is leaked, but it’s not. Ownership is transferred into the `ffi_cif` structure, and it’s eventually freed in `gi_callable_info_destroy_closure()`. Try and help the static analysis by adding an explicit ownership transfer annotation. It probably won’t help. Signed-off-by: Philip Withnall Helps: #1767 --- girepository/girffi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/girepository/girffi.c b/girepository/girffi.c index 053fd3439..1f3b4b282 100644 --- a/girepository/girffi.c +++ b/girepository/girffi.c @@ -339,7 +339,7 @@ gi_function_invoker_new_for_address (void *addr, return ffi_prep_cif (&(invoker->cif), FFI_DEFAULT_ABI, n_args, gi_callable_info_get_ffi_return_type (info), - atypes) == FFI_OK; + g_steal_pointer (&atypes)) == FFI_OK; } /** @@ -409,6 +409,11 @@ gi_callable_info_create_closure (GICallableInfo *callable_info, status = ffi_prep_cif (cif, FFI_DEFAULT_ABI, n_args, gi_callable_info_get_ffi_return_type (callable_info), atypes); + + /* Explicitly store atypes to satisfy static analysers, which can’t see inside + * ffi_prep_cif(), and hence assume that it’s leaked. */ + cif->arg_types = g_steal_pointer (&atypes); + if (status != FFI_OK) { g_warning ("ffi_prep_cif failed: %d", status);