# HG changeset patch # User Pierre-Yves David # Date 2017-06-12 15:21:41 # Node ID 336700745a5c08e63c454166db9c05a4d0dfb529 # Parent 54b356d650797ce766eff90bd135055ffa966aa5 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. diff --git a/mercurial/profiling.py b/mercurial/profiling.py --- a/mercurial/profiling.py +++ b/mercurial/profiling.py @@ -188,7 +188,7 @@ class profile(object): 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 @@ class profile(object): 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: