If USE_ZEND_ALLOC=0 valgrind /path/to/php arguments shows lots of errors like this:
==30030== Conditional jump or move depends on uninitialised value(s) ==30030== at 0x4047F2C: ??? ==30030== by 0x120D1630: ??? ==30030== by 0x120D15C7: ??? ==30030== by 0x120D1636: ??? ==30030== by 0x120D1A4F: ??? ==30030== by 0xAC9244: add_next_index_stringl (zend_API.c:1585) ==30030== Conditional jump or move depends on uninitialised value(s) ==30030== at 0x404766A: ??? ==30030== by 0x1268F850: ??? ==30030== by 0x1268F7E7: ??? ==30030== by 0x1268F851: ??? ==30030== by 0x127C0BBF: ??? ==30030== by 0xCA3157: ??? (in /path/to/php) ==30030== Conditional jump or move depends on uninitialised value(s) ==30030== at 0x403FFF4: ??? ==30030== by 0x11BEBBF7: ??? ==30030== by 0x11BEBBF7: ??? ==30030== by 0x11BEBC86: ??? ==30030== by 0x11BEF92F: ??? ==30030== by 0xA7BC9E: __zend_malloc (zend_alloc.c:2829)
This is probably because PCRE JIT support was enabled, and PCRE is unaware of Valgrind’s presence.
You usually see these errors when running PHPUnit (the first two, which appear before PHPUnit runs tests) or make test for a PHP extension (the last one).
See a more straightforward solution in Update 2 below.
To fix, PHP needs to be rebuilt with
./configure --with-valgrind --with-pcre-valgrind
Valgrind also shows me a bunch of memory leaks:
==2372== 48 bytes in 1 blocks are definitely lost in loss record 32 of 107 ==2372== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==2372== by 0xACE065: zend_register_functions (zend_API.c:2306) ==2372== by 0xACF7AE: do_register_internal_class (zend_API.c:2716) ==2372== by 0xACF9CE: zend_register_internal_class (zend_API.c:2764) ==2372== by 0xACF864: zend_register_internal_class_ex (zend_API.c:2736) ==2372== by 0x5109AF: zm_startup_dom (php_dom.c:780) ==2372== by 0xACC4B1: zend_startup_module_ex (zend_API.c:1873) ==2372== by 0xACC53B: zend_startup_module_zval (zend_API.c:1888) ==2372== by 0xADC1CA: zend_hash_apply (zend_hash.c:1506) ==2372== by 0xACCBDD: zend_startup_modules (zend_API.c:1999) ==2372== by 0x9F9388: php_module_startup (main.c:2309) ==2372== by 0xBC6B0A: php_cli_startup (php_cli.c:431) ==2372== by 0xBC919F: main (php_cli.c:1371)
They originate from the core, and unfortunately, I don’t have any solution other than suppression files.
UPDATE: The memory leak is a known bug that has already been fixed but not yet released (7.2.5).
UPDATE 2: There is a more straightforward solution: instead of rebuilding PHP (which is not always possible — for example, Travis CI’s PHP is not built with Valgrind support), it is enough to set pcre.jit = 0 in php.ini or invoke ini_set('pcre.jit', 0); early in the code.