Skip to content

Commit f0d783b

Browse files
committed
Free expanded filename in php_init_config()
This leak ends up getting suppressed, but is rather annoying when not using ZEND_TRACKED_ALLOC.
1 parent 3585f5a commit f0d783b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

main/php_ini.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@ int php_init_config(void)
404404
char *open_basedir;
405405
int free_ini_search_path = 0;
406406
zend_string *opened_path = NULL;
407-
FILE *fp;
408-
const char *filename;
409407

410408
zend_hash_init(&configuration_hash, 8, NULL, config_zval_dtor, 1);
411409

@@ -557,8 +555,9 @@ int php_init_config(void)
557555
* Find and open actual ini file
558556
*/
559557

560-
fp = NULL;
561-
filename = NULL;
558+
FILE *fp = NULL;
559+
char *filename = NULL;
560+
bool free_filename = false;
562561

563562
/* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
564563
* 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)
574573
fp = VCWD_FOPEN(php_ini_file_name, "r");
575574
if (fp) {
576575
filename = expand_filepath(php_ini_file_name, NULL);
576+
free_filename = true;
577577
}
578578
}
579579
}
@@ -624,6 +624,10 @@ int php_init_config(void)
624624
php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
625625
}
626626
zend_destroy_file_handle(&fh);
627+
628+
if (free_filename) {
629+
efree(filename);
630+
}
627631
}
628632

629633
/* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */

0 commit comments

Comments
 (0)