diff options
author | Wez Furlong <wez@php.net> | 2002-03-18 19:42:19 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2002-03-18 19:42:19 +0000 |
commit | 48e902bacd1979416b91abbea32e5f783213c966 (patch) | |
tree | 1b46269a90efa48f50facd855ff3421d2d52994c /main | |
parent | c978602a0b6048c4291a536f72621e7ac5b3d05b (diff) | |
download | php-git-48e902bacd1979416b91abbea32e5f783213c966.tar.gz |
Fix for bugs #16148, #11199, #10092:
fread from socket will never free memory.
This patch should also be applied to php_sockread_internal in
fsock.c in the 4.2 branch.
Diffstat (limited to 'main')
-rw-r--r-- | main/network.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/main/network.c b/main/network.c index e5bbbca57b..d8a69ebd67 100644 --- a/main/network.c +++ b/main/network.c @@ -633,6 +633,14 @@ static size_t php_sock_stream_read_internal(php_stream *stream, php_netstream_da #endif nr_bytes = recv(sock->socket, buf, sock->chunk_size, 0); if(nr_bytes > 0) { + + /* try to avoid ever expanding buffer */ + if (sock->readpos > 0) { + memmove(sock->readbuf, READPTR(sock), sock->readbuflen - sock->readpos); + sock->writepos -= sock->readpos; + sock->readpos = 0; + } + if(sock->writepos + nr_bytes > sock->readbuflen) { sock->readbuflen += sock->chunk_size; sock->readbuf = perealloc(sock->readbuf, sock->readbuflen, |