xref: /php-src/ext/ffi/tests/gh14626.phpt (revision 1ff277de)
1--TEST--
2GH-14626: FFI::free() may crash in is_zend_ptr() when at least one huge block exists and the ptr is non-zend
3--EXTENSIONS--
4ffi
5--SKIPIF--
6<?php
7if (substr(PHP_OS, 0, 3) == 'WIN') die("skip no malloc() on windows");
8?>
9--INI--
10ffi.enable=1
11--FILE--
12<?php
13
14// Ensure there is at least one huge_block
15$str = str_repeat('a', 2*1024*1024);
16
17$ffi = FFI::cdef(<<<C
18    void *malloc(size_t size);
19C);
20
21$ptr = $ffi->malloc(10);
22$addr = $ffi->cast("uintptr_t", $ffi->cast("char*", $ptr))->cdata;
23
24$ptr = FFI::cdef()->cast("char*", $addr);
25
26// Should not crash in is_zend_ptr()
27FFI::free($ptr);
28
29?>
30==DONE==
31--EXPECT--
32==DONE==
33