Skip to content

Commit 056bec7

Browse files
committed
Fix GH-14590: Memory leak in FPM test gh13563-conf-bool-env.phpt
Values retrieved from zend_getenv should be freed. Note: The only possible value for `zend_getenv` is `sapi_getenv` which uses zend alloc to duplicate the string that it reads from the SAPI module. Closes GH-14708.
1 parent 643762c commit 056bec7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed bug GH-13922 (Fixed support for systems with
77
sysconf(_SC_GETPW_R_SIZE_MAX) == -1). (Arnaud)
88
. Fixed bug GH-14626 (Fix is_zend_ptr() for huge blocks). (Arnaud)
9+
. Fixed bug GH-14590 (Memory leak in FPM test gh13563-conf-bool-env.phpt.
10+
(nielsdos)
911

1012
- Phar:
1113
. Fixed bug GH-14603 (null string from zip entry).

Zend/zend_ini_parser.y

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ static void zend_ini_get_var(zval *result, zval *name)
173173
if ((curval = zend_get_configuration_directive(Z_STR_P(name))) != NULL) {
174174
ZVAL_NEW_STR(result, zend_string_init(Z_STRVAL_P(curval), Z_STRLEN_P(curval), ZEND_SYSTEM_INI));
175175
/* ..or if not found, try ENV */
176-
} else if ((envvar = zend_getenv(Z_STRVAL_P(name), Z_STRLEN_P(name))) != NULL ||
177-
(envvar = getenv(Z_STRVAL_P(name))) != NULL) {
176+
} else if ((envvar = zend_getenv(Z_STRVAL_P(name), Z_STRLEN_P(name))) != NULL) {
177+
ZVAL_NEW_STR(result, zend_string_init(envvar, strlen(envvar), ZEND_SYSTEM_INI));
178+
efree(envvar);
179+
} else if ((envvar = getenv(Z_STRVAL_P(name))) != NULL) {
178180
ZVAL_NEW_STR(result, zend_string_init(envvar, strlen(envvar), ZEND_SYSTEM_INI));
179181
} else {
180182
zend_ini_init_string(result);

0 commit comments

Comments
 (0)