Skip to content

SplObjectStorage debug handler mismanages memory #18322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nielsdos opened this issue Apr 13, 2025 · 0 comments
Closed

SplObjectStorage debug handler mismanages memory #18322

nielsdos opened this issue Apr 13, 2025 · 0 comments

Comments

@nielsdos
Copy link
Member

Description

The following code:

<?php

$stor = new SplObjectStorage();
$obj = new stdClass;
$stor[$obj] = 1;

$tmp = $stor->__debugInfo();
$tmp2 = $tmp[array_key_first($tmp)];
unset($tmp); // Drop $tmp2 RC to 1
$tmp2[0]['obj'] = new stdClass;
var_dump($tmp2);

Resulted in this output:

A bunch of ASAN crap

But I expected this output instead:

Not that

The problem is that the code uses a hack rather than properly managing memory: Z_ARRVAL_P(&tmp)->pDestructor = NULL;...

PHP Version

8.3+

Operating System

No response

@nielsdos nielsdos self-assigned this Apr 13, 2025
nielsdos added a commit to nielsdos/php-src that referenced this issue Apr 14, 2025
This hack was once necessary before there was a proper get_gc handler,
but now it breaks the engine constraints.
nielsdos added a commit that referenced this issue Apr 14, 2025
* PHP-8.3:
  Fix GH-18322: SplObjectStorage debug handler mismanages memory
nielsdos added a commit that referenced this issue Apr 14, 2025
* PHP-8.4:
  Fix GH-18322: SplObjectStorage debug handler mismanages memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant