diff -r 54b356d65079 -r 336700745a5c mercurial/profiling.py --- 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: