Skip to content

SplObjectStorage debug handler mismanages memory #18322

Closed
@nielsdos

Description

@nielsdos

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions