Skip to content

Commit 641d96f

Browse files
committed
Fix memory leak caused by attribute validation and add test for class method deprecations.
1 parent c205daa commit 641d96f

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

Zend/tests/attributes/deprecated_001.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,34 @@ function test() {
1414
function test2() {
1515
}
1616

17+
class Clazz {
18+
#[Deprecated]
19+
function test() {
20+
}
21+
22+
#[Deprecated("use test() instead")]
23+
function test2() {
24+
}
25+
}
26+
1727
test();
1828
test2();
1929
call_user_func("test");
30+
31+
$cls = new Clazz();
32+
$cls->test();
33+
$cls->test2();
34+
35+
call_user_func([$cls, "test"]);
2036
--EXPECTF--
2137
Deprecated: Function test() is deprecated in %s
2238

2339
Deprecated: Function test2() is deprecated, use test() instead in %s
2440

2541
Deprecated: Function test() is deprecated in %s
42+
43+
Deprecated: Method Clazz::test() is deprecated in %s
44+
45+
Deprecated: Method Clazz::test2() is deprecated, use test() instead in %s
46+
47+
Deprecated: Method Clazz::test() is deprecated in %s
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
#[Deprecated] attribute with wrong type
3+
--FILE--
4+
<?php
5+
6+
#[Deprecated(1234)]
7+
function test() {
8+
}
9+
10+
11+
--EXPECTF--
12+
Fatal error: Deprecated::__construct: Argument #1 ($message) must be of type string, int given in %s

Zend/zend_attributes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ void validate_deprecated_attribute(zend_attribute *attr, uint32_t target, zend_c
7070
}
7171

7272
if (Z_TYPE(message) != IS_STRING) {
73+
zval_ptr_dtor(&message);
74+
7375
zend_error_noreturn(E_COMPILE_ERROR,
7476
"Deprecated::__construct: Argument #1 ($message) must be of type string, %s given",
7577
zend_zval_type_name(&message)
7678
);
7779
}
80+
81+
zval_ptr_dtor(&message);
7882
}
7983
}
8084

Zend/zend_execute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,8 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_functi
15181518
ZSTR_VAL(message_suffix)
15191519
);
15201520
}
1521+
1522+
zend_string_release(message_suffix);
15211523
} else {
15221524
if (fbc->common.scope) {
15231525
zend_error(E_DEPRECATED, "Method %s::%s() is deprecated",

0 commit comments

Comments
 (0)