diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1166,6 +1166,8 @@ def internalpatch(patchobj, ui, strip, c finally: if cwd: os.chdir(curdir) + if fp != patchobj: + fp.close() if ret < 0: raise PatchError return ret > 0