Skip to content

Commit

Permalink
Merge pull request #72 from BitOne/GITHUB-68_duplicate_objects_php7
Browse files Browse the repository at this point in the history
Fixes #68 by using object address instead of zval address
  • Loading branch information
BitOne committed Aug 8, 2018
2 parents 79dfa7c + 2f5ce98 commit b40dcca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion extension/php7/meminfo.c
Expand Up @@ -222,7 +222,11 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy
ZVAL_DEREF(zv);
}

sprintf(zval_id, "%p", zv);
if (Z_TYPE_P(zv) == IS_OBJECT) {
sprintf(zval_id, "%p", zv->value.obj);
} else {
sprintf(zval_id, "%p", zv);
}

if (meminfo_visit_item(zval_id, visited_items)) {
return;
Expand Down
33 changes: 33 additions & 0 deletions extension/php7/tests/bug-github-68_duplicate_objects_php7.phpt
@@ -0,0 +1,33 @@
--TEST--
Check that an object with multiple references is detected only once by meminfo.
--SKIPIF--
<?php
if (!extension_loaded('json')) die('skip json ext not loaded');
?>
--FILE--
<?php
$dump = fopen('php://memory', 'rw');

$a = new StdClass();
$b = $a;

$b->test = "foo";

meminfo_dump($dump);

rewind($dump);
$meminfoData = json_decode(stream_get_contents($dump), true);
fclose($dump);

$objectsCount = 0;
foreach($meminfoData['items'] as $item) {
if ($item['type'] === 'object') {
$objectsCount++;
}
}

echo "Objects count found by meminfo:".$objectsCount."\n";

?>
--EXPECT--
Objects count found by meminfo:1

0 comments on commit b40dcca

Please sign in to comment.