Fix module shutdown crash during ZTS JIT shutdown #10835
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Commit a211956 fixed a leak by adding a TSRM destructor for the JIT globals in ZTS mode. In case the main thread shuts down the TSRM, it will call all the destructors. The JIT globals destructor will be invoked, but will always access the main thread globals using JIT_G. This means that instead of freeing the JIT globals in the different threads, the one in the main thread is freed repeatedly over and over, crashing PHP. Fix it by always passing the pointer instead of relying on JIT_G.
This can be triggered reliably even when opcache is on. The JIT does not need to be enabled, because the JIT globals are always constructed. To reproduce this locally, I used an Apache worker/event MPM, and send a lot of requests using ApacheBench. Eventually you'll see the segfaults in the error_log file. You can also crash it by stopping the Apache server. Other SAPIs might be affected as well.
This bug exists only in 8.1.17RC1, 8.2.4RC1 and master.
Discovered while working on #10737