Skip to content

Commit 1f178f5

Browse files
committed
Copy params to fci
1 parent 4917e47 commit 1f178f5

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

Zend/tests/bug41026.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class try_class
1212

1313
static public function on_shutdown ()
1414
{
15-
printf ("CHECKPOINT\n");
15+
printf ("CHECKPOINT\n"); /* never reached */
1616
}
1717
}
1818

@@ -22,4 +22,5 @@ echo "Done\n";
2222
?>
2323
--EXPECT--
2424
Done
25-
CHECKPOINT
25+
26+
Fatal error: Registered shutdown function self::on_shutdown() cannot be called, function does not exist in Unknown on line 0

ext/standard/basic_functions.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ void user_shutdown_function_dtor(zval *zv) /* {{{ */
16711671
zval_ptr_dtor(&shutdown_function_entry->fci.params[i]);
16721672
}
16731673

1674+
efree(shutdown_function_entry->fci.params);
16741675
efree(shutdown_function_entry);
16751676
}
16761677
/* }}} */
@@ -1762,8 +1763,7 @@ PHPAPI void php_call_shutdown_functions(void) /* {{{ */
17621763
if (BG(user_shutdown_function_names)) {
17631764
zend_try {
17641765
zend_hash_apply(BG(user_shutdown_function_names), user_shutdown_function_call);
1765-
}
1766-
zend_end_try();
1766+
} zend_end_try();
17671767
}
17681768
}
17691769
/* }}} */
@@ -1786,24 +1786,22 @@ PHPAPI void php_free_shutdown_functions(void) /* {{{ */
17861786
/* {{{ Register a user-level function to be called on request termination */
17871787
PHP_FUNCTION(register_shutdown_function)
17881788
{
1789-
php_shutdown_function_entry *entry = emalloc(sizeof(php_shutdown_function_entry));
1790-
bool status = false;
1789+
php_shutdown_function_entry entry;
1790+
zval *params;
17911791

1792-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "f*", &entry->fci, &entry->fci_cache,
1793-
&entry->fci.params, &entry->fci.param_count) == FAILURE) {
1794-
efree(entry);
1795-
RETURN_THROWS();
1796-
}
1792+
ZEND_PARSE_PARAMETERS_START(1, -1)
1793+
Z_PARAM_FUNC(entry.fci, entry.fci_cache)
1794+
Z_PARAM_VARIADIC('+', params, entry.fci.param_count);
1795+
ZEND_PARSE_PARAMETERS_END();
17971796

1798-
Z_TRY_ADDREF(entry->fci.function_name);
1799-
for (size_t i = 0; i < entry->fci.param_count; i++) {
1800-
Z_TRY_ADDREF(entry->fci.params[i]);
1801-
}
1797+
entry.fci.params = emalloc(sizeof(zval) * entry.fci.param_count);
18021798

1803-
status = append_user_shutdown_function(entry);
1804-
ZEND_ASSERT(status);
1799+
Z_TRY_ADDREF(entry.fci.function_name);
1800+
for (size_t i = 0; i < entry.fci.param_count; i++) {
1801+
ZVAL_COPY(&entry.fci.params[i], &params[i]);
1802+
}
18051803

1806-
efree(entry);
1804+
ZEND_ASSERT(append_user_shutdown_function(&entry));
18071805
}
18081806
/* }}} */
18091807

0 commit comments

Comments
 (0)