Skip to content

Commit

Permalink
fix: SIGSEGV with env vars (#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alliballibaba2 authored Dec 21, 2024
1 parent 0fc6ccc commit 92f9534
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions phpmainthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ func initPHPThreads(numThreads int) error {
}
phpThreads = make([]*phpThread, numThreads)

if err := mainThread.start(); err != nil {
return err
}

// initialize all threads as inactive
// this needs to happen before starting the main thread
// since some extensions access environment variables on startup
for i := 0; i < numThreads; i++ {
phpThreads[i] = newPHPThread(i)
convertToInactiveThread(phpThreads[i])
}

if err := mainThread.start(); err != nil {
return err
}

// start the underlying C threads
ready := sync.WaitGroup{}
ready.Add(numThreads)
Expand Down
5 changes: 2 additions & 3 deletions phpthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ func (thread *phpThread) getActiveRequest() *http.Request {
// Pin a string that is not null-terminated
// PHP's zend_string may contain null-bytes
func (thread *phpThread) pinString(s string) *C.char {
if s == "" {
sData := unsafe.StringData(s)
if sData == nil {
return nil
}

sData := unsafe.StringData(s)
thread.Pin(sData)

return (*C.char)(unsafe.Pointer(sData))
Expand Down

0 comments on commit 92f9534

Please sign in to comment.