xref: /PHP-8.2/ext/ffi/tests/gh8433.phpt (revision a74b8651)
1--TEST--
2GH-8433 (Assigning function pointers to structs in FFI leaks memory)
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9
10$ffi = FFI::cdef("typedef struct { int a; } bar;");
11$x = $ffi->new("bar(*)(void)");
12FFI::addr($x)[0] = function() use ($ffi) {
13    $bar = $ffi->new("bar");
14    $bar->a = 2;
15    return $bar;
16};
17var_dump($x());
18
19?>
20--EXPECTF--
21object(FFI\CData:struct <anonymous>)#%d (1) {
22  ["a"]=>
23  int(2)
24}
25