diff mercurial/statprof.py @ 52606:f4d1f0713b49

statprof: don't leak a file descriptor when loading data files I wanted to use `util.readfiles()` here, but it looks like very little core code is imported, and I assume that's by design?
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 17 Dec 2024 01:35:52 -0500
parents ef83646d5f7d
children dc36535a5edc
line wrap: on
line diff
--- a/mercurial/statprof.py	Tue Dec 17 01:31:17 2024 -0500
+++ b/mercurial/statprof.py	Tue Dec 17 01:35:52 2024 -0500
@@ -397,7 +397,8 @@
 
 
 def load_data(path):
-    lines = open(path, 'rb').read().splitlines()
+    with open(path, 'rb') as fp:
+        lines = fp.read().splitlines()
 
     state.accumulated_time = [float(value) for value in lines[0].split()]
     state.samples = []