Re: com php-src: fix bug #76801: phpdbg too many open files error: NEWS sapi/phpdbg/phpdbg_list.c sapi/phpdbg/tests/bug76801.phpt
sapi/phpdbg/tests/empty.inc sapi/phpdbg/tests/include_once.phpt sapi/phpdbg/tests/include_once_001.phpt sapi/phpdbg/tests/include_once_002.phpt
| From: | Matteo Beccati | Date: | Fri, 29 Mar 2019 16:03:21 +0000 |
| Subject: | Re: com php-src: fix bug #76801: phpdbg too many open files error: NEWS sapi/phpdbg/phpdbg_list.c sapi/phpdbg/tests/bug76801.phpt sapi/phpdbg/tests/empty.inc sapi/phpdbg/tests/include_once.phpt sapi/phpdbg/tests/include_once_001.phpt sapi/phpdbg/tests/include_once_002.phpt |
||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-105404@lists.php.net to get a copy of this message | ||
Hi Joe, Alessandro,
the test is triggering quite a few memory leaks on my CI:
https://revive.beccati.com/bamboo/browse/PHP-SRC7-TESTS-515/test/case/48535215
103+ /home/atlassian/bamboo/xml-data/build-dir/PHP-SRC7-BUIL/Zend/zend_opcode.c(59) : Freeing 0x00007f617880d000 (4 bytes), script=-
104+ Last leak repeated 3977 times
105+ [Fri Mar 29 01:37:47 2019] Script: '-'
106+ /home/atlassian/bamboo/xml-data/build-dir/PHP-SRC7-BUIL/sapi/phpdbg/phpdbg_list.c(249) : Freeing 0x00007f617880d028 (1 bytes), script=-
107+ Last leak repeated 3977 times
108+ === Total 124995 memory leaks detected ===
109+ prompt>
Cheers
On 23/03/2019 09:47, Joe Watkins wrote:
-- Matteo Beccati Development & Consulting - http://www.beccati.com/Commit: b8b880932e95ff1e575a04a6988bc0cf00b89842 Author: Alessandro Chitolina <alekitto@gmail.com> Tue, 19 Mar 2019 17:34:34 +0100 Committer: Joe Watkins <krakjoe@php.net> Sat, 23 Mar 2019 09:47:49 +0100Parents: 2e9dccef78d169be9a4a37c813e0b5d624bd5ac7 Branches: PHP-7.2 PHP-7.3 PHP-7.4 masterLink: http://git.php.net/?p=php-src.git;a=commitdiff;h=b8b880932e95ff1e575a04a6988bc0cf00b89842Log: fix bug #76801: phpdbg too many open files error Bugs: https://bugs.php.net/76801 Changed paths: M NEWS M sapi/phpdbg/phpdbg_list.c A sapi/phpdbg/tests/bug76801.phpt A sapi/phpdbg/tests/empty.inc D sapi/phpdbg/tests/include_once.phpt A sapi/phpdbg/tests/include_once_001.phpt A sapi/phpdbg/tests/include_once_002.phpt Diff: diff --git a/NEWS b/NEWS index dbce1af..d2e5043 100644 --- a/NEWS +++ b/NEWS@@ -2,6 +2,9 @@ PHP NEWS||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2019, PHP 7.2.18 +- phpdbg: + . Fixed bug #76801 (too many open files). (alekitto) + - Reflection:. Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita) diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.cindex 865f75b..cb0250e 100644 --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@ -234,33 +234,33 @@ void phpdbg_list_function_byname(const char *str, size_t len) /* {{{ */ /* Note: do not free the original file handler, let original compile_file() or caller do that. Caller may rely on its value to check success */ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) { phpdbg_file_source data, *dataptr; - zend_file_handle fake; zend_op_array *ret; - char *filename; uint32_t line; char *bufptr, *endptr; + int size; - if (zend_stream_fixup(file, &bufptr, &data.len) == FAILURE) { - return PHPDBG_G(compile_file)(file, type); + ret = PHPDBG_G(compile_file)(file, type); + if (ret == NULL) { + return ret; } - filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename); + if (file->type == ZEND_HANDLE_MAPPED) { + data.len = file->handle.stream.mmap.len; + data.buf = emalloc(data.len + 1); + memcpy(data.buf, file->handle.stream.mmap.buf, data.len); + } else { + if (file->type == ZEND_HANDLE_FILENAME) { + zend_stream_open(file->filename, file); + } - data.buf = emalloc(data.len + ZEND_MMAP_AHEAD + 1); - if (data.len > 0) { - memcpy(data.buf, bufptr, data.len); + size = file->handle.stream.fsizer(file->handle.stream.handle); + data.buf = emalloc(size + 1); + data.len = file->handle.stream.reader(file->handle.stream.handle, data.buf, size); } - memset(data.buf + data.len, 0, ZEND_MMAP_AHEAD + 1); - data.line[0] = 0; - memset(&fake, 0, sizeof(fake)); - fake.type = ZEND_HANDLE_MAPPED; - fake.handle.stream.mmap.buf = data.buf; - fake.handle.stream.mmap.len = data.len; - fake.free_filename = 0; - fake.filename = filename; - fake.opened_path = file->opened_path; + memset(data.buf + data.len, 0, 1); + data.line[0] = 0; *(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint32_t) * data.len)) = data; for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) { @@ -268,28 +268,14 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) { dataptr->line[++line] = (uint32_t)(bufptr - data.buf) + 1; } } + dataptr->lines = ++line; + dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint32_t) * line); dataptr->line[line] = endptr - data.buf; - ret = PHPDBG_G(compile_file)(&fake, type); - - if (ret == NULL) { - efree(data.buf); - efree(dataptr); - - fake.opened_path = NULL; - zend_file_handle_dtor(&fake); - - return NULL; - } - - dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint32_t) * line); zend_hash_add_ptr(&PHPDBG_G(file_sources), ret->filename, dataptr); phpdbg_resolve_pending_file_break(ZSTR_VAL(ret->filename)); - fake.opened_path = NULL; - zend_file_handle_dtor(&fake); - return ret; } diff --git a/sapi/phpdbg/tests/bug76801.phpt b/sapi/phpdbg/tests/bug76801.phpt new file mode 100644 index 0000000..12ec8c7 --- /dev/null +++ b/sapi/phpdbg/tests/bug76801.phpt @@ -0,0 +1,15 @@ +--TEST-- +include()ing files should not raise "too many open files" error +--PHPDBG-- +r +q +--EXPECTF-- +[Successful compilation of %s] +prompt> [Script ended normally] +prompt> +--FILE-- +<?php + +for ($i = 0; $i < 25000; ++$i) {+ include __DIR__.'/empty.inc';+} diff --git a/sapi/phpdbg/tests/empty.inc b/sapi/phpdbg/tests/empty.inc new file mode 100644 index 0000000..e69de29 diff --git a/sapi/phpdbg/tests/include_once.phpt b/sapi/phpdbg/tests/include_once.phpt deleted file mode 100644 index b91f5e8..0000000 --- a/sapi/phpdbg/tests/include_once.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -include_once must include only once ---PHPDBG-- -r -q ---EXPECTF-- -[Successful compilation of %s] -prompt> 1 -[Script ended normally] -prompt> ---FILE-- -<?php - -include_once __DIR__.'/include.inc'; -include_once __DIR__.'/include.inc'; diff --git a/sapi/phpdbg/tests/include_once_001.phpt b/sapi/phpdbg/tests/include_once_001.phpt new file mode 100644 index 0000000..b91f5e8 --- /dev/null +++ b/sapi/phpdbg/tests/include_once_001.phpt @@ -0,0 +1,15 @@ +--TEST-- +include_once must include only once +--PHPDBG-- +r +q +--EXPECTF-- +[Successful compilation of %s] +prompt> 1 +[Script ended normally] +prompt> +--FILE-- +<?php + +include_once __DIR__.'/include.inc'; +include_once __DIR__.'/include.inc'; diff --git a/sapi/phpdbg/tests/include_once_002.phpt b/sapi/phpdbg/tests/include_once_002.phpt new file mode 100644 index 0000000..742decf --- /dev/null +++ b/sapi/phpdbg/tests/include_once_002.phpt @@ -0,0 +1,15 @@ +--TEST-- +include_once must include only once #2 +--PHPDBG-- +r +q +--EXPECTF-- +[Successful compilation of %s] +prompt> 1 +[Script ended normally] +prompt> +--FILE-- +<?php + +include __DIR__.'/include.inc'; +include_once __DIR__.'/include.inc';