From 7b7ce542d2030a8e63624ff980725186d781d72b Mon Sep 17 00:00:00 2001 From: Benoit Jacquemont Date: Wed, 8 Aug 2018 10:02:31 +0200 Subject: [PATCH] Fixes #70 by indirecting before dereferecing zval --- extension/php7/meminfo.c | 15 ++++--- ...g-github-49_escape_control_character.phpt} | 0 ...> bug-github-63_php7_wrong_exec_fame.phpt} | 0 ...-70_duplicated_referenced_scalar_php7.phpt | 39 +++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) rename extension/php7/tests/{bug-git-49_escape_control_character.phpt => bug-github-49_escape_control_character.phpt} (100%) rename extension/php7/tests/{bug-git-63_php7_wrong_exec_fame.phpt => bug-github-63_php7_wrong_exec_fame.phpt} (100%) create mode 100644 extension/php7/tests/bug-github-70_duplicated_referenced_scalar_php7.phpt diff --git a/extension/php7/meminfo.c b/extension/php7/meminfo.c index 9791963..dff802b 100644 --- a/extension/php7/meminfo.c +++ b/extension/php7/meminfo.c @@ -213,6 +213,15 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * symbol_name, zval * zv, HashTable *visited_items, int *first_element) { char zval_id[16]; + + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + + if (Z_ISREF_P(zv)) { + ZVAL_DEREF(zv); + } + sprintf(zval_id, "%p", zv); if (meminfo_visit_item(zval_id, visited_items)) { @@ -225,12 +234,6 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy *first_element = 0; } - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); - } else if (Z_ISREF_P(zv)) { - ZVAL_DEREF(zv); - } - php_stream_printf(stream TSRMLS_CC, " \"%s\" : {\n", zval_id); php_stream_printf(stream TSRMLS_CC, " \"type\" : \"%s\",\n", zend_get_type_by_const(Z_TYPE_P(zv))); php_stream_printf(stream TSRMLS_CC, " \"size\" : \"%ld\",\n", meminfo_get_element_size(zv)); diff --git a/extension/php7/tests/bug-git-49_escape_control_character.phpt b/extension/php7/tests/bug-github-49_escape_control_character.phpt similarity index 100% rename from extension/php7/tests/bug-git-49_escape_control_character.phpt rename to extension/php7/tests/bug-github-49_escape_control_character.phpt diff --git a/extension/php7/tests/bug-git-63_php7_wrong_exec_fame.phpt b/extension/php7/tests/bug-github-63_php7_wrong_exec_fame.phpt similarity index 100% rename from extension/php7/tests/bug-git-63_php7_wrong_exec_fame.phpt rename to extension/php7/tests/bug-github-63_php7_wrong_exec_fame.phpt diff --git a/extension/php7/tests/bug-github-70_duplicated_referenced_scalar_php7.phpt b/extension/php7/tests/bug-github-70_duplicated_referenced_scalar_php7.phpt new file mode 100644 index 0000000..e7a19da --- /dev/null +++ b/extension/php7/tests/bug-github-70_duplicated_referenced_scalar_php7.phpt @@ -0,0 +1,39 @@ +--TEST-- +Check that a scalar with multiple references is detected only once by meminfo. +--SKIPIF-- + +--FILE-- + +--EXPECT-- +Reference 'b' not found.