Skip to content

Commit ec1cb37

Browse files
committed
Fix memory leak of function attribute hash table
==109253== 280 (56 direct, 224 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 4 ==109253== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==109253== by 0x6D9FA2: __zend_malloc (zend_alloc.c:3068) ==109253== by 0x745138: zend_add_attribute (zend_attributes.c:226) ==109253== by 0x6680D1: zend_add_parameter_attribute (zend_attributes.h:102) ==109253== by 0x66B787: zm_startup_zend_test (test.c:478) ==109253== by 0x7224CD: zend_startup_module_ex (zend_API.c:2202) ==109253== by 0x72252C: zend_startup_module_zval (zend_API.c:2217) ==109253== by 0x734288: zend_hash_apply (zend_hash.c:2011) ==109253== by 0x722C30: zend_startup_modules (zend_API.c:2328) ==109253== by 0x67409B: php_module_startup (main.c:2256) ==109253== by 0x88EDDE: php_cli_startup (php_cli.c:409) ==109253== by 0x890F61: main (php_cli.c:1334)
1 parent 53a687d commit ec1cb37

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Zend/zend_opcode.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ ZEND_API void zend_function_dtor(zval *zv)
156156
/* For methods this will be called explicitly. */
157157
if (!function->common.scope) {
158158
zend_free_internal_arg_info(&function->internal_function);
159+
160+
if (function->common.attributes) {
161+
zend_hash_release(function->common.attributes);
162+
function->common.attributes = NULL;
163+
}
159164
}
160165

161166
if (!(function->common.fn_flags & ZEND_ACC_ARENA_ALLOCATED)) {
@@ -433,11 +438,17 @@ ZEND_API void destroy_zend_class(zval *zv)
433438
zend_hash_destroy(&ce->properties_info);
434439
zend_string_release_ex(ce->name, 1);
435440

436-
/* TODO: eliminate this loop for classes without functions with arg_info */
441+
/* TODO: eliminate this loop for classes without functions with arg_info / attributes */
437442
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, fn) {
438-
if ((fn->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS)) &&
439-
fn->common.scope == ce) {
440-
zend_free_internal_arg_info(&fn->internal_function);
443+
if (fn->common.scope == ce) {
444+
if (fn->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS)) {
445+
zend_free_internal_arg_info(&fn->internal_function);
446+
}
447+
448+
if (fn->common.attributes) {
449+
zend_hash_release(fn->common.attributes);
450+
fn->common.attributes = NULL;
451+
}
441452
}
442453
} ZEND_HASH_FOREACH_END();
443454

0 commit comments

Comments
 (0)