From 95e513f95a39756dc930c056aee6d7ea1b96c8cc Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 23 May 2017 15:16:23 -0700 Subject: Close stdout and stderr when spawning a process (#3578) --- tests/hazmat/backends/test_openssl_memleak.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/hazmat/backends/test_openssl_memleak.py b/tests/hazmat/backends/test_openssl_memleak.py index e4cbd0fb..53c41375 100644 --- a/tests/hazmat/backends/test_openssl_memleak.py +++ b/tests/hazmat/backends/test_openssl_memleak.py @@ -102,15 +102,19 @@ def assert_no_memory_leaks(s, argv=[]): stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) - proc.wait() - if proc.returncode == 255: - # 255 means there was a leak, load the info about what mallocs weren't - # freed. - out = json.loads(proc.stdout.read().decode()) - raise AssertionError(out) - elif proc.returncode != 0: - # Any exception type will do to be honest - raise ValueError(proc.stdout.read(), proc.stderr.read()) + try: + proc.wait() + if proc.returncode == 255: + # 255 means there was a leak, load the info about what mallocs + # weren't freed. + out = json.loads(proc.stdout.read().decode()) + raise AssertionError(out) + elif proc.returncode != 0: + # Any exception type will do to be honest + raise ValueError(proc.stdout.read(), proc.stderr.read()) + finally: + proc.stdout.close() + proc.stderr.close() def skip_if_memtesting_not_supported(): -- cgit v1.2.3