girffi: Add hints to indicate ownership transfer into ffi_cif

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 <pwithnall@gnome.org>

Helps: #1767
This commit is contained in:
Philip Withnall 2024-04-10 00:20:24 +01:00
parent e2c3581e37
commit 4141eea257
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -339,7 +339,7 @@ gi_function_invoker_new_for_address (void *addr,
return ffi_prep_cif (&(invoker->cif), FFI_DEFAULT_ABI, n_args, return ffi_prep_cif (&(invoker->cif), FFI_DEFAULT_ABI, n_args,
gi_callable_info_get_ffi_return_type (info), 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, status = ffi_prep_cif (cif, FFI_DEFAULT_ABI, n_args,
gi_callable_info_get_ffi_return_type (callable_info), gi_callable_info_get_ffi_return_type (callable_info),
atypes); atypes);
/* Explicitly store atypes to satisfy static analysers, which cant see inside
* ffi_prep_cif(), and hence assume that its leaked. */
cif->arg_types = g_steal_pointer (&atypes);
if (status != FFI_OK) if (status != FFI_OK)
{ {
g_warning ("ffi_prep_cif failed: %d", status); g_warning ("ffi_prep_cif failed: %d", status);