Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 13400:14f3795a5ed7
explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 24 Dec 2010 15:23:01 +0100 |
parents | 777cef34a890 |
children | d724a69309e0 |
line wrap: on
line diff
--- a/mercurial/util.py Fri Feb 11 22:24:10 2011 +0800 +++ b/mercurial/util.py Fri Dec 24 15:23:01 2010 +0100 @@ -198,7 +198,10 @@ if code: raise Abort(_("command '%s' failed: %s") % (cmd, explain_exit(code))) - return open(outname, 'rb').read() + fp = open(outname, 'rb') + r = fp.read() + fp.close() + return r finally: try: if inname: @@ -591,7 +594,10 @@ raise except AttributeError: # no symlink in os pass - return posixfile(pathname).read() + fp = posixfile(pathname) + r = fp.read() + fp.close() + return r def fstat(fp): '''stat file object that may not have fileno method.'''