Skip to content

Commit 3b5bfd9

Browse files
decsnynashif
authored andcommitted
scripts: check_compliance: Fix resource leak
The git diff subprocess was leaking, ie., it was still running with it's file streams open, and python was printing warnings about this. Fix by calling communicate() on the object which will do the cleanup. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 402adc4 commit 3b5bfd9

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

scripts/ci/check_compliance.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -291,37 +291,37 @@ def run(self):
291291
cmd = [checkpatch]
292292

293293
cmd.extend(['--mailback', '--no-tree', '-'])
294-
diff = subprocess.Popen(('git', 'diff', '--no-ext-diff', COMMIT_RANGE),
294+
with subprocess.Popen(('git', 'diff', '--no-ext-diff', COMMIT_RANGE),
295295
stdout=subprocess.PIPE,
296-
cwd=GIT_TOP)
297-
try:
298-
subprocess.run(cmd,
299-
check=True,
300-
stdin=diff.stdout,
301-
stdout=subprocess.PIPE,
302-
stderr=subprocess.STDOUT,
303-
shell=False, cwd=GIT_TOP)
296+
cwd=GIT_TOP) as diff:
297+
try:
298+
subprocess.run(cmd,
299+
check=True,
300+
stdin=diff.stdout,
301+
stdout=subprocess.PIPE,
302+
stderr=subprocess.STDOUT,
303+
shell=False, cwd=GIT_TOP)
304304

305-
except subprocess.CalledProcessError as ex:
306-
output = ex.output.decode("utf-8")
307-
regex = r'^\s*\S+:(\d+):\s*(ERROR|WARNING):(.+?):(.+)(?:\n|\r\n?)+' \
308-
r'^\s*#(\d+):\s*FILE:\s*(.+):(\d+):'
305+
except subprocess.CalledProcessError as ex:
306+
output = ex.output.decode("utf-8")
307+
regex = r'^\s*\S+:(\d+):\s*(ERROR|WARNING):(.+?):(.+)(?:\n|\r\n?)+' \
308+
r'^\s*#(\d+):\s*FILE:\s*(.+):(\d+):'
309309

310-
matches = re.findall(regex, output, re.MULTILINE)
310+
matches = re.findall(regex, output, re.MULTILINE)
311311

312-
# add a guard here for excessive number of errors, do not try and
313-
# process each one of them and instead push this as one failure.
314-
if len(matches) > 500:
315-
self.failure(output)
316-
return
312+
# add a guard here for excessive number of errors, do not try and
313+
# process each one of them and instead push this as one failure.
314+
if len(matches) > 500:
315+
self.failure(output)
316+
return
317317

318-
for m in matches:
319-
self.fmtd_failure(m[1].lower(), m[2], m[5], m[6], col=None,
320-
desc=m[3])
318+
for m in matches:
319+
self.fmtd_failure(m[1].lower(), m[2], m[5], m[6], col=None,
320+
desc=m[3])
321321

322-
# If the regex has not matched add the whole output as a failure
323-
if len(matches) == 0:
324-
self.failure(output)
322+
# If the regex has not matched add the whole output as a failure
323+
if len(matches) == 0:
324+
self.failure(output)
325325

326326

327327
class BoardYmlCheck(ComplianceTest):

0 commit comments

Comments
 (0)