changeset 32828:062eb859d3ee

profile: close 'fp' in all cases There are no way for this to happen today, but better be safe than sorry, no one know how the code will evolve. We now make sure the file pointer is closed even is profiler is None.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 12 Jun 2017 17:25:37 +0200
parents 336700745a5c
children 6675d23da748
files mercurial/profiling.py
diffstat 1 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/profiling.py	Mon Jun 12 17:21:41 2017 +0200
+++ b/mercurial/profiling.py	Mon Jun 12 17:25:37 2017 +0200
@@ -214,15 +214,14 @@
             raise
 
     def __exit__(self, exception_type, exception_value, traceback):
-        if self._profiler is None:
-            return
-        self._profiler.__exit__(exception_type, exception_value, traceback)
-        if self._output == 'blackbox':
-            val = 'Profile:\n%s' % self._fp.getvalue()
-            # ui.log treats the input as a format string,
-            # so we need to escape any % signs.
-            val = val.replace('%', '%%')
-            self._ui.log('profile', val)
+        if self._profiler is not None:
+            self._profiler.__exit__(exception_type, exception_value, traceback)
+            if self._output == 'blackbox':
+                val = 'Profile:\n%s' % self._fp.getvalue()
+                # ui.log treats the input as a format string,
+                # so we need to escape any % signs.
+                val = val.replace('%', '%%')
+                self._ui.log('profile', val)
         self._closefp()
 
     def _closefp(self):