Skip to content

Commit

Permalink
function: Allocate ffi_arg_pointers using an unique_ptr array
Browse files Browse the repository at this point in the history
As commit before, better not to use alloca(), while we've c++ handling
the lifetime of our array.
  • Loading branch information
3v1n0 authored and ptomato committed Nov 22, 2020
1 parent ac0b11a commit a6c9432
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gi/function.cpp
Expand Up @@ -778,7 +778,7 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
// index inside ffi_arg_pointers.
GjsFunctionCallState state(context, function->info, gi_argc);

void** ffi_arg_pointers = g_newa(void*, ffi_argc);
auto ffi_arg_pointers = std::make_unique<void*[]>(ffi_argc);

failed = false;
unsigned ffi_arg_pos = 0; // index into ffi_arg_pointers
Expand Down Expand Up @@ -873,7 +873,7 @@ static bool gjs_invoke_c_function(JSContext* context, Function* function,
return_value_p = get_return_ffi_pointer_from_giargument(
&function->arguments[-1], &return_value);
ffi_call(&(function->invoker.cif), FFI_FN(function->invoker.native_address),
return_value_p, ffi_arg_pointers);
return_value_p, ffi_arg_pointers.get());

/* Return value and out arguments are valid only if invocation doesn't
* return error. In arguments need to be released always.
Expand Down

0 comments on commit a6c9432

Please sign in to comment.