Skip to content

Commit

Permalink
Drop free_filename field from zend_file_handle
Browse files Browse the repository at this point in the history
free_filename was always zero.
  • Loading branch information
nikic committed Jul 16, 2019
1 parent 49bac9b commit e0eca26
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 17 deletions.
3 changes: 0 additions & 3 deletions Zend/zend_language_scanner.l
Expand Up @@ -292,9 +292,6 @@ 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)
Expand Down
5 changes: 0 additions & 5 deletions Zend/zend_stream.c
Expand Up @@ -116,7 +116,6 @@ ZEND_API int zend_stream_open(const char *filename, zend_file_handle *handle) /*
handle->opened_path = NULL;
handle->handle.fp = zend_fopen(filename, &handle->opened_path);
handle->filename = filename;
handle->free_filename = 0;
memset(&handle->handle.stream.mmap, 0, sizeof(zend_mmap));

return (handle->handle.fp) ? SUCCESS : FAILURE;
Expand Down Expand Up @@ -261,10 +260,6 @@ ZEND_API void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
zend_string_release_ex(fh->opened_path, 0);
fh->opened_path = NULL;
}
if (fh->free_filename && fh->filename) {
efree((char*)fh->filename);
fh->filename = NULL;
}
}
/* }}} */

Expand Down
1 change: 0 additions & 1 deletion Zend/zend_stream.h
Expand Up @@ -65,7 +65,6 @@ typedef struct _zend_file_handle {
const char *filename;
zend_string *opened_path;
zend_stream_type type;
zend_bool free_filename;
} zend_file_handle;

BEGIN_EXTERN_C()
Expand Down
1 change: 0 additions & 1 deletion ext/phar/phar.c
Expand Up @@ -3261,7 +3261,6 @@ 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:
Expand Down
1 change: 0 additions & 1 deletion main/main.c
Expand Up @@ -1585,7 +1585,6 @@ PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *h
if (stream) {
handle->type = ZEND_HANDLE_STREAM;
handle->filename = (char*)filename;
handle->free_filename = 0;
handle->handle.stream.handle = stream;
handle->handle.stream.reader = (zend_stream_reader_t)_php_stream_read;
handle->handle.stream.fsizer = php_zend_stream_fsizer;
Expand Down
2 changes: 0 additions & 2 deletions sapi/litespeed/lsapi_main.c
Expand Up @@ -1313,7 +1313,6 @@ 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) {
Expand All @@ -1324,7 +1323,6 @@ 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);
Expand Down
4 changes: 0 additions & 4 deletions sapi/phpdbg/phpdbg_list.c
Expand Up @@ -294,10 +294,6 @@ 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;
}
}
Expand Down

18 comments on commit e0eca26

@Jan-E
Copy link
Contributor

@Jan-E Jan-E commented on e0eca26 Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikic This should be documented in UPGRADING.INTERNALS
@petk @EricSten-MSFT This is the commit that breaks Wincache in 7.4-beta1

@Jan-E
Copy link
Contributor

@Jan-E Jan-E commented on e0eca26 Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EricSten-MSFT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WinCache is estrdup()'ing a filename into the zend_file_handle during its stream open, and we're assuming that whomever free's the handle will need to do the efree() on that memory. Is there some other way to signal that whomever frees the file handle needs to free the filename pointer?

Is there a PHP_API_VERSION version number change to go with this breaking change? I see that 20190529 is the current value in the main/php.h file, but that was the same number as php-7.4.0alpha1. Otherwise I won't be able to compile for both before and after php-7.4.0beta1.

@nikic
Copy link
Member Author

@nikic nikic commented on e0eca26 Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EricSten-MSFT As long as you set opened_path (which I believe you do), just setting filename to NULL (and thus no need to estrdup anything) should be fine.

@nikic
Copy link
Member Author

@nikic nikic commented on e0eca26 Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this turns out to be too troublesome it would be possible to add free_filename back (I wasn't aware it's used by wincache). I'd just like to explore not having it first, because it seems like an unnecessary complication on both sides.

@EricSten-MSFT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The memory for the string used by opened_path is actually the allocation from filename, so one way or the other, when the zend_file_handle gets freed, the memory needs to get free'd. I don't know how many other extensions are implementing their own stream open handler and returning their own zend_file_handles, but they must run into the same problem, since they don't own the code that does the free'ing of the returned object.

So, I'm going to say, yeah, it will be too troublesome to unwind this. I would greatly appreciate your patience, and hope that you will revert this change. Thx!

@dstogov
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose, wincache should work in the same way as opcache, so it probably may be fixed, or both should have the same problem.

@EricSten-MSFT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like opcache always deals with interned strings, so it never has to worry about cleaning up the memory. However, WinCache (for reasons before my time) has its own resolve cache, and every time a stream_open happens, it allocates the filename based upon whatever is returned from the resolve cache. It therefore needs whomever free's up the zend_file_handle to also free up the filename.

@nikic
Copy link
Member Author

@nikic nikic commented on e0eca26 Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this tomorrow and either come up with a way to make wincache work without free_filename, or revert the change.

@Jan-E
Copy link
Contributor

@Jan-E Jan-E commented on e0eca26 Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the changes in the commit, there are almost no benefits by the removal. And for extensions that use it the hurdles are high. I agree with @EricSten-MSFT that a revert would be best. If it is reverted, please do a new release of beta1 before the official announcement.

@nikic
Copy link
Member Author

@nikic nikic commented on e0eca26 Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change reverted in d968027.

@Jan-E
Copy link
Contributor

@Jan-E Jan-E commented on e0eca26 Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Will you make a new release tarball? The one at github is still from yesterday.

@petk
Copy link
Member

@petk petk commented on e0eca26 Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @derickr (the tarballs are otherwise planned for the Thursday to be "final", exactly for cases like this).

@derickr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see if I can roll some new ones right away.

@EricSten-MSFT — we'll bump the API number with RC1. Before that, the API doesn't have to be stable yet.

@derickr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petk
Copy link
Member

@petk petk commented on e0eca26 Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fast. Thank you @derickr

@Jan-E
Copy link
Contributor

@Jan-E Jan-E commented on e0eca26 Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd already noticed. Compiling the new beta1 nts x64 vs16 ATM.

@Jan-E
Copy link
Contributor

@Jan-E Jan-E commented on e0eca26 Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix confirmed. Thanks to all.

Please sign in to comment.