changeset 52599:006feec78d52

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 17 Dec 2024 00:47:42 -0500
parents 34eb9c877c2e
children cac851655570
files mercurial/crecord.py
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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