Skip to content

Commit

Permalink
Fixed bug #78902
Browse files Browse the repository at this point in the history
  • Loading branch information
liudaixiao authored and nikic committed Jan 23, 2020
1 parent f720fb1 commit 67421a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions ext/standard/tests/streams/bug78902.phpt
Original file line number Diff line number Diff line change
@@ -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--
Expand Down
11 changes: 9 additions & 2 deletions main/streams/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 67421a7

Please sign in to comment.