procutil: don't leak a file descriptor when I/O fails filtering through files
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 17 Dec 2024 01:45:29 -0500
changeset 52582 1b9b6b4aa929
parent 52581 cc918741a22a
child 52583 8de9bab826bc
procutil: don't leak a file descriptor when I/O fails filtering through files
mercurial/utils/procutil.py
--- 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)