fix leaking streams and memory mapped files

(cherry picked from commit f1ff23095b)
This commit is contained in:
Anatol Belski 2016-12-11 02:52:02 +01:00
parent a32829f909
commit 9cdf64c225

View file

@ -3270,19 +3270,31 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type)
/* zip or tar-based phar */ /* zip or tar-based phar */
spprintf(&name, 4096, "phar://%s/%s", file_handle->filename, ".phar/stub.php"); spprintf(&name, 4096, "phar://%s/%s", file_handle->filename, ".phar/stub.php");
if (SUCCESS == phar_orig_zend_open((const char *)name, file_handle)) { if (SUCCESS == phar_orig_zend_open((const char *)name, &f)) {
efree(name); efree(name);
name = NULL; name = NULL;
file_handle->filename = f.filename;
if (file_handle->opened_path) { f.filename = file_handle->filename;
efree(file_handle->opened_path); if (f.opened_path) {
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:
case ZEND_HANDLE_MAPPED:
if (file_handle->handle.stream.closer && file_handle->handle.stream.handle) {
file_handle->handle.stream.closer(file_handle->handle.stream.handle);
}
file_handle->handle.stream.handle = NULL;
break;
} }
file_handle->opened_path = f.opened_path;
file_handle->free_filename = f.free_filename;
} else {
*file_handle = f; *file_handle = f;
} }
} else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) { } else if (phar->flags & PHAR_FILE_COMPRESSION_MASK) {
zend_file_handle_dtor(file_handle);
/* compressed phar */ /* compressed phar */
file_handle->type = ZEND_HANDLE_STREAM; file_handle->type = ZEND_HANDLE_STREAM;
/* we do our own reading directly from the phar, don't change the next line */ /* we do our own reading directly from the phar, don't change the next line */