aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-04-14 22:18:01 -0400
committerMike Frysinger <vapier@google.com>2021-04-14 22:18:01 -0400
commitbfa656d5880fc887fd5eba0d2fbabb1bd8faceb8 (patch)
tree9725a7a3307e1cf5d42ca41233d74ec81a6afa03
parenta89a1380979c491642d8e6080969ce54b0f38031 (diff)
downloadrepohooks-bfa656d5880fc887fd5eba0d2fbabb1bd8faceb8.tar.gz
utils: run: fix file leakage with bad execs
Minor issue that doesn't normally show up, but should still make sure we explicitly close these handles so the resource trackers don't warn. Bug: 185196437 Test: unittests pass Change-Id: I6e64a10243c2d20245e37d090e1c167067f0f13c
-rw-r--r--rh/utils.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/rh/utils.py b/rh/utils.py
index 4d17bb8..96512ed 100644
--- a/rh/utils.py
+++ b/rh/utils.py
@@ -416,6 +416,12 @@ def run(cmd, redirect_stdout=False, redirect_stderr=False, cwd=None, input=None,
stdout=ensure_text(result.stdout),
stderr=ensure_text(result.stderr))
except OSError as e:
+ # Avoid leaking tempfiles.
+ if popen_stdout is not None:
+ popen_stdout.close()
+ if popen_stderr is not None:
+ popen_stderr.close()
+
estr = str(e)
if e.errno == errno.EACCES:
estr += '; does the program need `chmod a+x`?'