--- a/mercurial/patch.py Sun Jan 03 18:16:42 2010 +0100 +++ b/mercurial/patch.py Sun Jan 03 20:36:30 2010 +0100 @@ -1166,6 +1166,8 @@ finally: if cwd: os.chdir(curdir) + if fp != patchobj: + fp.close() if ret < 0: raise PatchError return ret > 0