From 8969b8496af2fbde0fc2bb63ce3db71edd8d7475 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 15 Jun 2020 10:51:55 -0700 Subject: Wrap SCons.Action._subproc() call with 'with' to prevent leaking popen object --- SCons/Tool/gcc.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/SCons/Tool/gcc.py b/SCons/Tool/gcc.py index 79b64f0..b530db2 100644 --- a/SCons/Tool/gcc.py +++ b/SCons/Tool/gcc.py @@ -77,22 +77,23 @@ def detect_version(env, cc): # GCC versions older than that, we should use --version and a # regular expression. # pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'], - pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], + with SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], stdin='devnull', stderr='devnull', - stdout=subprocess.PIPE) - if pipe.wait() != 0: - return version + stdout=subprocess.PIPE) as pipe: + if pipe.wait() != 0: + return version + + with pipe.stdout: + # -dumpversion variant: + # line = pipe.stdout.read().strip() + # --version variant: + line = SCons.Util.to_str(pipe.stdout.readline()) + # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: + # So continue with reading to let the child process actually terminate. + while SCons.Util.to_str(pipe.stdout.readline()): + pass - with pipe.stdout: - # -dumpversion variant: - # line = pipe.stdout.read().strip() - # --version variant: - line = SCons.Util.to_str(pipe.stdout.readline()) - # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: - # So continue with reading to let the child process actually terminate. - while SCons.Util.to_str(pipe.stdout.readline()): - pass # -dumpversion variant: # if line: -- cgit v0.12