From 46ea033de0bdd52e042bade5b7bc026193003368 Mon Sep 17 00:00:00 2001 From: Adrian Panasiuk Date: Wed, 4 Aug 2021 21:25:33 +0200 Subject: [PATCH] fixup! Don't leak compressed stream (#630) --- smart_open/compression.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/smart_open/compression.py b/smart_open/compression.py index 2ddc9557..b3b9c638 100644 --- a/smart_open/compression.py +++ b/smart_open/compression.py @@ -72,10 +72,12 @@ def adapted_closer(adapter, adapted): def close_both(*args): nonlocal adapted - orig_close() - if adapted: - adapted.close() - adapted = None + try: + orig_close() + finally: + if adapted: + adapted, fp = None, adapted + fp.close() adapter.close = close_both return adapter