Commit 858d729
Fix ZTS heap corruption by calling php_module_startup only once
The previous code called php_module_startup() per-thread via
Sapi::startup(), but this function is only meant to be called once
during application initialization. Calling it multiple times caused
heap corruption in PHP's memory allocator, manifesting as
EXC_BAD_ACCESS (code=2) crashes in _estrdup on macOS aarch64.
The correct ZTS lifecycle is:
1. php_module_startup() - once at app init (in Sapi::new())
2. ts_resource(0) - per-thread TLS init (in ThreadScope::new())
3. php_request_startup()/shutdown() - per-request (in RequestScope)
Sapi::startup() now only verifies the SAPI is accessible (read lock)
rather than reinitializing PHP modules.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>1 parent eac0104 commit 858d729
2 files changed
+19
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | | - | |
345 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
346 | 347 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
354 | | - | |
355 | 354 | | |
356 | 355 | | |
357 | 356 | | |
| |||
361 | 360 | | |
362 | 361 | | |
363 | 362 | | |
364 | | - | |
365 | 363 | | |
366 | | - | |
367 | 364 | | |
368 | 365 | | |
369 | 366 | | |
370 | 367 | | |
371 | | - | |
372 | 368 | | |
373 | | - | |
374 | 369 | | |
375 | 370 | | |
376 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
123 | 130 | | |
124 | | - | |
| 131 | + | |
125 | 132 | | |
126 | 133 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
0 commit comments