Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/common.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 | f64b416b0ac8 |
children | 75f5f312df5f |
line wrap: on
line diff
--- a/mercurial/hgweb/common.py Fri Feb 11 22:24:10 2011 +0800 +++ b/mercurial/hgweb/common.py Fri Dec 24 15:23:01 2010 +0100 @@ -119,7 +119,10 @@ os.stat(path) ct = mimetypes.guess_type(path)[0] or "text/plain" req.respond(HTTP_OK, ct, length = os.path.getsize(path)) - return open(path, 'rb').read() + fp = open(path, 'rb') + data = fp.read() + fp.close() + return data except TypeError: raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') except OSError, err: