Skip to content

Commit ccb29a6

Browse files
committed
Fixed bug #66334 (Memory Leak in new pass1_5.c optimizations). (Terry)
1 parent 8650d2d commit ccb29a6

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

ext/opcache/Optimizer/pass1_5.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,11 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
383383
zend_module_entry *m;
384384
char *lc_name = zend_str_tolower_dup(
385385
Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)), Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)));
386+
int found = zend_hash_find(&module_registry,
387+
lc_name, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)) + 1, (void *)&m) == SUCCESS;
386388

387-
if (zend_hash_find(&module_registry,
388-
lc_name, Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)) + 1, (void *)&m) == FAILURE) {
389+
efree(lc_name);
390+
if (!found) {
389391
if (!PG(enable_dl)) {
390392
break;
391393
} else {
@@ -405,7 +407,6 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
405407
literal_dtor(&ZEND_OP1_LITERAL(opline));
406408
MAKE_NOP(opline);
407409
}
408-
efree(lc_name);
409410
} else if (Z_STRLEN(ZEND_OP1_LITERAL(opline)) == sizeof("defined")-1 &&
410411
!memcmp(Z_STRVAL(ZEND_OP1_LITERAL(opline)),
411412
"defined", sizeof("defined")-1)) {

ext/opcache/tests/bug66334.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #66334 (Memory Leak in new pass1_5.c optimizations)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.file_update_protection=0
8+
enable_dl=0
9+
--SKIPIF--
10+
<?php require_once('skipif.inc'); ?>
11+
--FILE--
12+
<?php
13+
if (extension_loaded("unknown_extension")) {
14+
var_dump(1);
15+
} else {
16+
var_dump(2);
17+
}
18+
--EXPECT--
19+
int(2)

0 commit comments

Comments
 (0)