From bd1234f227a27e5ab506c15782a32d8b5055ec35 Mon Sep 17 00:00:00 2001 From: Eric Blundell Date: Tue, 20 Mar 2018 09:02:17 -0500 Subject: [PATCH] fix open file leak in client.download_media --- pyrogram/client/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index a53225a0..57351887 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -2248,6 +2248,8 @@ class Client: elif isinstance(file_out, str): f = open(file_out, 'wb') + close_file = True + elif hasattr(file_out, 'write'): f = file_out @@ -2367,7 +2369,7 @@ class Client: else: return file_out finally: - if close_file and f and hasattr(f, 'close'): + if close_file and f is not None: f.close() session.stop()