changeset 32808:336700745a5c

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 12 Jun 2017 17:21:41 +0200
parents 54b356d65079
children 062eb859d3ee
files mercurial/profiling.py
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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: