Skip to content

docs(prop): document the Exception::getMessage refcount leak#737

Draft
ptondereau wants to merge 1 commit into
extphprs:masterfrom
ptondereau:fix/string-prop-getter-zend-string-leak
Draft

docs(prop): document the Exception::getMessage refcount leak#737
ptondereau wants to merge 1 commit into
extphprs:masterfrom
ptondereau:fix/string-prop-getter-zend-string-leak

Conversation

@ptondereau
Copy link
Copy Markdown
Member

@ptondereau ptondereau commented May 13, 2026

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 one zend_string each time PHP's Exception::getMessage reads 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 the rv slot.

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 via zend_update_property_stringl. The proper fix is bigger and out of scope here, either an upstream PHP patch to dtor the rv slot 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

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.
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 25812964747

Coverage remained the same at 66.23%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 13065
Covered Lines: 8653
Line Coverage: 66.23%
Coverage Strength: 33.38 hits per line

💛 - Coveralls

@github-actions
Copy link
Copy Markdown

🐰 Bencher Report

Branchfix/string-prop-getter-zend-string-leak
TestbedPHP 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.

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

🐰 View full continuous benchmarking report in Bencher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants