[PATCH 5 of 7] profile: close 'fp' on error within '__enter__'
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Jun 12 12:17:49 EDT 2017
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1497280901 -7200
# Mon Jun 12 17:21:41 2017 +0200
# Node ID 6db777ef801754d7f97006f865c41408f3bfc300
# Parent 0f3d18d09dd1c744a1158b1d2b6b881f87fac391
# EXP-Topic profile
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
# hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 6db777ef8017
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:
More information about the Mercurial-devel
mailing list