Skip to content

Commit 1386ca2

Browse files
committed
Fix memory leak
We need to free interfaces names before we overwrite their counter.
1 parent eba9a20 commit 1386ca2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Zend/zend_inheritance.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,14 +2232,6 @@ static void zend_do_implement_interfaces(zend_class_entry *ce, zend_class_entry
22322232
}
22332233
}
22342234

2235-
if (!(ce->ce_flags & ZEND_ACC_CACHED)) {
2236-
for (i = 0; i < ce->num_interfaces; i++) {
2237-
zend_string_release_ex(ce->interface_names[i].name, 0);
2238-
zend_string_release_ex(ce->interface_names[i].lc_name, 0);
2239-
}
2240-
efree(ce->interface_names);
2241-
}
2242-
22432235
ce->num_interfaces = num_interfaces;
22442236
ce->interfaces = interfaces;
22452237
ce->ce_flags |= ZEND_ACC_RESOLVED_INTERFACES;
@@ -3597,6 +3589,14 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
35973589
Z_CE_P(zv) = ce;
35983590
}
35993591

3592+
if (!(ce->ce_flags & ZEND_ACC_CACHED)) {
3593+
for (i = 0; i < ce->num_interfaces; i++) {
3594+
zend_string_release_ex(ce->interface_names[i].name, 0);
3595+
zend_string_release_ex(ce->interface_names[i].lc_name, 0);
3596+
}
3597+
efree(ce->interface_names);
3598+
}
3599+
36003600
ce->num_interfaces = num_implementable_interfaces;
36013601

36023602
if (CG(unlinked_uses)) {
@@ -3642,6 +3642,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
36423642
} else if (parent && parent->num_interfaces) {
36433643
zend_do_inherit_interfaces(ce, parent);
36443644
}
3645+
36453646
if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT))
36463647
&& (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
36473648
) {

0 commit comments

Comments
 (0)