From: Nikita Popov Date: Wed, 24 Jul 2019 08:42:19 +0000 (+0200) Subject: Revert "Drop free_filename field from zend_file_handle" X-Git-Tag: php-7.4.0beta2~57 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9680272c78453a832ef02f914efa13c2545eb19;p=php Revert "Drop free_filename field from zend_file_handle" This reverts commit e0eca262852dba1a78afcde64a49126c81fead1a. free_filename is used by the wincache extension, restore this field for PHP 7.4. --- diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index fadd2f2a50..1537fa36f8 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -292,6 +292,9 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle) zend_llist_del_element(&CG(open_files), file_handle, (int (*)(void *, void *)) zend_compare_file_handles); /* zend_file_handle_dtor() operates on the copy, so we have to NULLify the original here */ file_handle->opened_path = NULL; + if (file_handle->free_filename) { + file_handle->filename = NULL; + } } ZEND_API void zend_lex_tstring(zval *zv) diff --git a/Zend/zend_stream.c b/Zend/zend_stream.c index a3490ffc93..4dffc31040 100644 --- a/Zend/zend_stream.c +++ b/Zend/zend_stream.c @@ -223,6 +223,10 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */ efree(fh->buf); fh->buf = NULL; } + if (fh->free_filename && fh->filename) { + efree((char*)fh->filename); + fh->filename = NULL; + } } /* }}} */ diff --git a/Zend/zend_stream.h b/Zend/zend_stream.h index 66a7e5198c..51651add38 100644 --- a/Zend/zend_stream.h +++ b/Zend/zend_stream.h @@ -56,6 +56,9 @@ typedef struct _zend_file_handle { const char *filename; zend_string *opened_path; zend_stream_type type; + /* free_filename is used by wincache */ + /* TODO: Clean up filename vs opened_path mess */ + zend_bool free_filename; char *buf; size_t len; } zend_file_handle; diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 0deec63368..93a0387366 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -3261,6 +3261,7 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type) efree(f.opened_path); } f.opened_path = file_handle->opened_path; + f.free_filename = file_handle->free_filename; switch (file_handle->type) { case ZEND_HANDLE_STREAM: diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index a851212c85..f7d4b1a84c 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -1338,6 +1338,7 @@ static int cli_main( int argc, char * argv[] ) highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini); } else if (source_highlight == 2) { file_handle.filename = *p; + file_handle.free_filename = 0; file_handle.opened_path = NULL; ret = php_lint_script(&file_handle); if (ret==SUCCESS) { @@ -1348,6 +1349,7 @@ static int cli_main( int argc, char * argv[] ) } else { file_handle.filename = *p; + file_handle.free_filename = 0; file_handle.opened_path = NULL; php_execute_script(&file_handle); diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c index fe612be325..03b4c3526e 100644 --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@ -294,6 +294,10 @@ zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) { zend_string_release(file->opened_path); file->opened_path = zend_string_init(filename, strlen(filename), 0); } else { + if (file->free_filename) { + efree((char *) file->filename); + } + file->free_filename = 0; file->filename = filename; } }