profile: close 'fp' on error within '__enter__'
Previously, error when initialying the profiler would forgot to explicitly
close the file. Thank goes to Yuya Nishihara for spotting this.
--- a/mercurial/profiling.py Mon Jun 12 17:20:48 2017 +0200
+++ b/mercurial/profiling.py Mon Jun 12 17:21:41 2017 +0200
@@ -188,7 +188,7 @@
self._output = self._ui.config('profiling', 'output')
- if True:
+ try:
if self._output == 'blackbox':
self._fp = util.stringio()
elif self._output:
@@ -209,6 +209,9 @@
self._profiler = proffn(self._ui, self._fp)
self._profiler.__enter__()
+ except: # re-raises
+ self._closefp()
+ raise
def __exit__(self, exception_type, exception_value, traceback):
if self._profiler is None: