From f0d783b7bf0757ce417739fada178ced1f7372d9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 9 Apr 2021 16:28:12 +0200 Subject: [PATCH] Free expanded filename in php_init_config() This leak ends up getting suppressed, but is rather annoying when not using ZEND_TRACKED_ALLOC. --- main/php_ini.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main/php_ini.c b/main/php_ini.c index 043644d4aac..abdc3aa78e5 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -404,8 +404,6 @@ int php_init_config(void) char *open_basedir; int free_ini_search_path = 0; zend_string *opened_path = NULL; - FILE *fp; - const char *filename; zend_hash_init(&configuration_hash, 8, NULL, config_zval_dtor, 1); @@ -557,8 +555,9 @@ int php_init_config(void) * Find and open actual ini file */ - fp = NULL; - filename = NULL; + FILE *fp = NULL; + char *filename = NULL; + bool free_filename = false; /* If SAPI does not want to ignore all ini files OR an overriding file/path is given. * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still @@ -574,6 +573,7 @@ int php_init_config(void) fp = VCWD_FOPEN(php_ini_file_name, "r"); if (fp) { filename = expand_filepath(php_ini_file_name, NULL); + free_filename = true; } } } @@ -624,6 +624,10 @@ int php_init_config(void) php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp)); } zend_destroy_file_handle(&fh); + + if (free_filename) { + efree(filename); + } } /* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */