From 0b9f82447294c9023a5000c86d1a39381b990d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA?= Date: Sun, 3 Mar 2019 23:13:10 +0500 Subject: [PATCH] Fix memory leak in chunked streams handling code (#3631) --- CHANGES/3631.bugfix | 1 + aiohttp/streams.py | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 CHANGES/3631.bugfix diff --git a/CHANGES/3631.bugfix b/CHANGES/3631.bugfix new file mode 100644 index 00000000000..1acb123c4b2 --- /dev/null +++ b/CHANGES/3631.bugfix @@ -0,0 +1 @@ +Cleanup per-chunk data in generic data read. Memory leak fixed. diff --git a/aiohttp/streams.py b/aiohttp/streams.py index be7da4b4f36..062aa80702d 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -460,6 +460,10 @@ def _read_nowait_chunk(self, n: int) -> bytes: self._size -= len(data) self._cursor += len(data) + # Prevent memory leak: drop useless chunk splits + while self._http_chunk_splits and self._http_chunk_splits[0] < self._cursor: + self._http_chunk_splits.pop() + if self._size < self._low_water and self._protocol._reading_paused: self._protocol.resume_reading() return data