Files
archived-frankenphp/ext.go
YL 11160fb7b3 fix: segmentation fault when registering multiple extensions (#2112)
This PR fixes a segmentation fault when using
frankenphp.RegisterExtension with more than one extension.
The issue was a type mismatch between Go and C: Go passes a slice of
pointers, but the C code was treating it as a contiguous array of
structs. This caused invalid memory access when iterating past the first
element.
I created a minimal reproduction repo here:
[https://github.com/y-l-g/frankenphp-extensions-segfault-repro](https://www.google.com/url?sa=E&q=https%3A%2F%2Fgithub.com%2Fy-l-g%2Ffrankenphp-extensions-segfault-repro)
2026-01-07 09:21:03 +01:00

30 lines
541 B
Go

package frankenphp
//#include "frankenphp.h"
import "C"
import (
"sync"
"unsafe"
)
var (
extensions []*C.zend_module_entry
registerOnce sync.Once
)
// RegisterExtension registers a new PHP extension.
func RegisterExtension(me unsafe.Pointer) {
extensions = append(extensions, (*C.zend_module_entry)(me))
}
func registerExtensions() {
if len(extensions) == 0 {
return
}
registerOnce.Do(func() {
C.register_extensions((**C.zend_module_entry)(unsafe.Pointer(&extensions[0])), C.int(len(extensions)))
extensions = nil
})
}