changeset 52608:1b9b6b4aa929

procutil: don't leak a file descriptor when I/O fails filtering through files
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 17 Dec 2024 01:45:29 -0500
parents cc918741a22a
children 8de9bab826bc
files mercurial/utils/procutil.py
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/utils/procutil.py	Tue Dec 17 01:39:33 2024 -0500
+++ b/mercurial/utils/procutil.py	Tue Dec 17 01:45:29 2024 -0500
@@ -328,9 +328,10 @@
     inname, outname = None, None
     try:
         infd, inname = pycompat.mkstemp(prefix=b'hg-filter-in-')
-        fp = os.fdopen(infd, 'wb')
-        fp.write(s)
-        fp.close()
+
+        with os.fdopen(infd, 'wb') as fp:
+            fp.write(s)
+
         outfd, outname = pycompat.mkstemp(prefix=b'hg-filter-out-')
         os.close(outfd)
         cmd = cmd.replace(b'INFILE', inname)