From 4b97c6065043e4268425bebec35f5c3722f73c2e Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Wed, 30 Mar 2022 18:16:20 +0200 Subject: compilers/gnu: use Popen_safe to prevent resource leaks Fixes the following ResourceWarnings: ResourceWarning: subprocess 25556 is still running _warn("subprocess %s is still running" % self.pid, ResourceWarning: Enable tracemalloc to get the object allocation traceback mesonbuild/compilers/mixins/gnu.py:195: ResourceWarning: unclosed file <_io.BufferedReader name=4> return gnulike_default_include_dirs(tuple(self.exelist), self.language).copy() ResourceWarning: Enable tracemalloc to get the object allocation traceback --- mesonbuild/compilers/mixins/gnu.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index b91788c..91e07e5 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -106,14 +106,7 @@ def gnulike_default_include_dirs(compiler: T.Tuple[str, ...], lang: str) -> 'Imm env = os.environ.copy() env["LC_ALL"] = 'C' cmd = list(compiler) + [f'-x{lang}', '-E', '-v', '-'] - p = subprocess.Popen( - cmd, - stdin=subprocess.DEVNULL, - stderr=subprocess.STDOUT, - stdout=subprocess.PIPE, - env=env - ) - stdout = p.stdout.read().decode('utf-8', errors='replace') + _, stdout, _ = mesonlib.Popen_safe(cmd, stderr=subprocess.STDOUT, env=env) parse_state = 0 paths = [] # type: T.List[str] for line in stdout.split('\n'): -- cgit v1.1