From 92a04546f9ba59a8516d9267812c6aea597cc700 Mon Sep 17 00:00:00 2001 From: Lazarev Ivan Date: Tue, 20 Dec 2016 11:26:01 +0300 Subject: [PATCH] Fix memory leak of Stream objects in HTTP20Connection --- apns2/client.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apns2/client.py b/apns2/client.py index 6da69f4..98f8961 100644 --- a/apns2/client.py +++ b/apns2/client.py @@ -37,7 +37,8 @@ class APNsClient(object): url = '/3/device/{}'.format(token_hex) stream_id = self.__connection.request('POST', url, json_payload, headers) resp = self.__connection.get_response(stream_id) - if resp.status != 200: - raw_data = resp.read().decode('utf-8') - data = json.loads(raw_data) - raise exception_class_for_reason(data['reason']) + with resp: + if resp.status != 200: + raw_data = resp.read().decode('utf-8') + data = json.loads(raw_data) + raise exception_class_for_reason(data['reason'])