From 056bec72f434008960c3375ac13223b622d73305 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 28 Jun 2024 21:09:17 +0200 Subject: [PATCH] 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. --- NEWS | 2 ++ Zend/zend_ini_parser.y | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 5fbbf907339..37f76cef3db 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ PHP NEWS . Fixed bug GH-13922 (Fixed support for systems with sysconf(_SC_GETPW_R_SIZE_MAX) == -1). (Arnaud) . Fixed bug GH-14626 (Fix is_zend_ptr() for huge blocks). (Arnaud) + . Fixed bug GH-14590 (Memory leak in FPM test gh13563-conf-bool-env.phpt. + (nielsdos) - Phar: . Fixed bug GH-14603 (null string from zip entry). diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y index 2d4e949d5c4..7ade9792cce 100644 --- a/Zend/zend_ini_parser.y +++ b/Zend/zend_ini_parser.y @@ -173,8 +173,10 @@ static void zend_ini_get_var(zval *result, zval *name) if ((curval = zend_get_configuration_directive(Z_STR_P(name))) != NULL) { ZVAL_NEW_STR(result, zend_string_init(Z_STRVAL_P(curval), Z_STRLEN_P(curval), ZEND_SYSTEM_INI)); /* ..or if not found, try ENV */ - } else if ((envvar = zend_getenv(Z_STRVAL_P(name), Z_STRLEN_P(name))) != NULL || - (envvar = getenv(Z_STRVAL_P(name))) != NULL) { + } else if ((envvar = zend_getenv(Z_STRVAL_P(name), Z_STRLEN_P(name))) != NULL) { + ZVAL_NEW_STR(result, zend_string_init(envvar, strlen(envvar), ZEND_SYSTEM_INI)); + efree(envvar); + } else if ((envvar = getenv(Z_STRVAL_P(name))) != NULL) { ZVAL_NEW_STR(result, zend_string_init(envvar, strlen(envvar), ZEND_SYSTEM_INI)); } else { zend_ini_init_string(result);