fix(types): better zval handling to avoid leaks with arrays by alexandre-daubois · Pull Request #1780 · php/frankenphp

zval := C.__zval_alloc__()
var zval C.zval

You don't need to allocate here. In order to avoid leaking, you just need to declare the zval and then pass a reference, PHP will handle allocation

var zval C.zval

switch v := value.(type) {
	case nil:
		C.__zval_null__(&zval)
	case bool:
		C.__zval_bool__(&zval, C._Bool(v))
	case int:
		C.__zval_long__(&zval, C.zend_long(v))
        case ...

When running PHP in debug mode (built with --enable-debug like in the dev.Dockerfile) you should see something like this when there is a leak between requests:

Last leak repeated 2 times
=== Total 3 memory leaks detected ===
[Fri Aug  1 21:58:55 2025]  Script:  '-'