[php-src] Issue #8433: Assigning function pointers to structs in FFI leaks memory

From: Date: Sun, 24 Apr 2022 01:26:56 +0000
Subject: [php-src] Issue #8433: Assigning function pointers to structs in FFI leaks memory
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241208@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8433 Author: bwoebi ### Description The following code: ```php <?php $ffi = FFI::cdef("typedef struct { int a; } bar;"); $x = $ffi->new("bar(*)(void)"); FFI::addr($x)[0] = fn() => $ffi->new("bar"); var_dump($x()); ``` Resulted in these memory leaks: ``` object(FFI\CData:struct <anonymous>)#5 (1) { ["a"]=> int(0) } [Sun Apr 24 03:13:26 2022] Script: 'Standard input code' /Users/bob/php-src/ext/ffi/ffi.c(244) : Freeing 0x000000010c857400 (88 bytes), script=Standard input code [Sun Apr 24 03:13:26 2022] Script: 'Standard input code' /Users/bob/php-src/ext/ffi/ffi.c(365) : Freeing 0x000000010c85daf0 (40 bytes), script=Standard input code === Total 2 memory leaks detected === ``` The first memory leak comes from calling (each call leaks memory - there seems to be a missing zval_ptr_dtor(ret); in zend_ffi_callback_trampoline). The second leak comes from the fake struct type not being freed. ### PHP Version master ### Operating System _No response_

« previous php.bugs (#241208) next »