docs(prop): document the Exception::getMessage refcount leak#737
Draft
ptondereau wants to merge 1 commit into
Draft
docs(prop): document the Exception::getMessage refcount leak#737ptondereau wants to merge 1 commit into
ptondereau wants to merge 1 commit into
Conversation
Hit this while building a PHPStan rule on top of biscuit-php and noticing memory growing on every datalog parse error. Tracking it down: any `#[php(prop)]` field holding an owned refcounted type (String, Vec, etc.) leaks one zend_string per call when PHP's Exception::getMessage reads it. Direct property access (`$obj->prop`) is unaffected — only the `zval_get_string + RETURN_STR` pattern used by Exception's final C methods triggers the orphaned refcount. Adds a regression test (marked `#[ignore]` so CI stays green) and documentation on the `#[php(prop)]` attribute with two workarounds: either rename the shadow field, or mirror to the parent's real slot via `zend_update_property_stringl`. Proper fix needs either an upstream PHP patch or a deeper change to how field props store their value.
Coverage Report for CI Build 25812964747Coverage remained the same at 66.23%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
| Branch | fix/string-prop-getter-zend-string-leak |
| Testbed | PHP 8.4.21 (cli) (built: May 8 2026 04:58:07) (NTS) |
⚠️ WARNING: Truncated view!The full continuous benchmarking report exceeds the maximum length allowed on this platform.
🐰 View full continuous benchmarking report in Bencher
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Spotted this while building a PHPStan rule on top of biscuit-php and watching memory grow on every datalog parse error. Drilling in: any
#[php(prop)]field holding an owned refcounted type leaks onezend_stringeach time PHP'sException::getMessagereads it. Direct property access from PHP code is unaffected; the leak only fires through Exception's final C methods, which assume real property storage and orphan the refcount we put in thervslot.This PR ships the regression test (marked
#[ignore]so CI stays green) and adds docs on the#[php(prop)]attribute with two workarounds: rename the shadow field or mirror the value into the parent's real slot viazend_update_property_stringl. The proper fix is bigger and out of scope here, either an upstream PHP patch to dtor thervslot or a deeper change to how field props store their value.Opening as a draft for visibility while we settle the long-term direction.
Checklist