Skip to content

fix: FutureStringArray::await() returns dangling CData instead of owned PHP strings (#36) - #60

Merged
s2x merged 1 commit into
masterfrom
fix/issue-36-futurestringarray-dangling-cdata
Jul 3, 2026
Merged

fix: FutureStringArray::await() returns dangling CData instead of owned PHP strings (#36)#60
s2x merged 1 commit into
masterfrom
fix/issue-36-futurestringarray-dangling-cdata

Conversation

@s2x

@s2x s2x commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Problem

FutureStringArray::await() indexes char** directly ([]), which returns an FFI\CData pointer — not a PHP string. After releaseMemory() those pointers become dangling (use-after-free). This is the public path behind ReadTransaction::getAddressesForKey().

Fix

Replaced raw char* indexing with FFI::string() to copy each element into an owned PHP string before the future's memory is released — same pattern already used in FutureKeyArray::await().

Changes

File Change
src/Future/FutureStringArray.php FFI::string([]) instead of raw pointer assignment
tests/Integration/BasicCrudTest.php getAddressesForKey() test now verifies elements are real strings matching host:port format
CHANGELOG.md Entry added

Verification

  • ✅ PHPStan level 9 — 0 new errors
  • ✅ Integration tests require FoundationDB cluster (CI will validate)

Closes #36

…ng CData (#36)

Use FFI::string() to copy char* elements into owned PHP strings before
the future's memory is released. Previously, raw FFI\CData pointers were
returned and became dangling after releaseMemory(), causing use-after-free
in getAddressesForKey() and any other consumer.

Also strengthens the getAddressesForKey integration test to verify that
returned elements are real strings matching host:port format.
@s2x
s2x merged commit 2d05c61 into master Jul 3, 2026
5 of 6 checks passed
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.

[Bug] FutureStringArray returns dangling CData instead of PHP strings

1 participant