crecord: don't leak a file descriptor when I/O fails
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 17 Dec 2024 00:47:42 -0500
changeset 52573 006feec78d52
parent 52572 34eb9c877c2e
child 52574 cac851655570
crecord: don't leak a file descriptor when I/O fails Also put a comment here, because I initially thought opening in non-binary mode was a mistake, but 7cc913396f8c did it purposely.
mercurial/crecord.py
--- a/mercurial/crecord.py	Mon Dec 16 21:30:02 2024 -0500
+++ b/mercurial/crecord.py	Tue Dec 17 00:47:42 2024 -0500
@@ -622,10 +622,10 @@
 
     chunkselector.stdscr = dummystdscr()
     if testfn and os.path.exists(testfn):
-        testf = open(testfn, 'r')
-        # TODO: open in binary mode?
-        testcommands = [x.rstrip('\n') for x in testf.readlines()]
-        testf.close()
+        # This file is purposely NOT opened in binary mode
+        with open(testfn, 'r') as testf:
+            testcommands = [x.rstrip('\n') for x in testf.readlines()]
+
         while True:
             if chunkselector.handlekeypressed(testcommands.pop(0), test=True):
                 break