Skip to content

Conversation

@realFlowControl
Copy link
Collaborator

No description provided.

This change ensures that shared array literals in the parallel cache are correctly
separated (copied) when modified within a thread.

By setting the initial refcount of shared persistent arrays (literals) to 2
and clearing the IS_TYPE_REFCOUNTED flag on the corresponding zvals, we force
the PHP VM to treat them as shared/immutable for modification purposes
(triggering COW), while preventing the VM from attempting non-atomic refcount
increments and decrements that would lead to heap corruption and crashes.

For private persistent arrays (e.g., closure static variables), we use
standard refcounting (initial refcount 1) and enable proper destruction when
the refcount drops to 0. This avoids memory leaks for non-recursive cases.

The dtor logic in src/copy.c is reverted to expect a refcount of 0 for
destruction, which aligns with standard refcounting behavior.

Fixes the corruption reported in tests/functional/008.phpt, avoids the
race conditions seen in tests/base/063.phpt, and addresses memory leaks in
standard closure usage.
@realFlowControl realFlowControl force-pushed the florian/refcount branch 3 times, most recently from 0d36410 to e4003af Compare December 23, 2025 14:38
@realFlowControl realFlowControl deleted the florian/refcount branch December 23, 2025 14:43
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