diff options
author | liudaixiao <dinosaur.liu@gmail.com> | 2019-12-16 09:10:28 +0800 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-01-23 14:57:16 +0100 |
commit | 67421a780d670ea2eec8157c39f2682bb3cfb7dd (patch) | |
tree | d6387e34b7c03fb334176632b169411f16872311 | |
parent | f720fb1e21f374bf84f5f6ce295175f369bc1291 (diff) | |
download | php-git-67421a780d670ea2eec8157c39f2682bb3cfb7dd.tar.gz |
Fixed bug #78902
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/standard/tests/streams/bug78902.phpt | 2 | ||||
-rw-r--r-- | main/streams/streams.c | 11 |
3 files changed, 12 insertions, 4 deletions
@@ -29,6 +29,9 @@ PHP NEWS . Fixed bug #79151 (heap use after free caused by spl_dllist_it_helper_move_forward). (Nikita) +- Standard: + . Fixed bug #78902 (Memory leak when using stream_filter_append). (liudaixiao) + 23 Jan 2020, PHP 7.3.14 - Core diff --git a/ext/standard/tests/streams/bug78902.phpt b/ext/standard/tests/streams/bug78902.phpt index 43b271fe27..1216c89bc2 100644 --- a/ext/standard/tests/streams/bug78902.phpt +++ b/ext/standard/tests/streams/bug78902.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #78902: Memory leak when using stream_filter_append ---XFAIL-- -This bug was introduced in PHP 7.3.11 an is still open --INI-- memory_limit=512k --FILE-- diff --git a/main/streams/streams.c b/main/streams/streams.c index 705f3bc633..5daf4fe83d 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -577,8 +577,15 @@ PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size) * stream read buffer */ while (brig_inp->head) { bucket = brig_inp->head; - /* grow buffer to hold this bucket - * TODO: this can fail for persistent streams */ + /* reduce buffer memory consumption if possible, to avoid a realloc */ + if (stream->readbuf && stream->readbuflen - stream->writepos < bucket->buflen) { + if (stream->writepos > stream->readpos) { + memmove(stream->readbuf, stream->readbuf + stream->readpos, stream->writepos - stream->readpos); + } + stream->writepos -= stream->readpos; + stream->readpos = 0; + } + /* grow buffer to hold this bucket */ if (stream->readbuflen - stream->writepos < bucket->buflen) { stream->readbuflen += bucket->buflen; stream->readbuf = perealloc(stream->readbuf, stream->readbuflen, |