# HG changeset patch # User Matt Harbison # Date 2024-09-20 04:20:24 # Node ID f833ad92ee44899db0e394534bbf595775f6dcb1 # Parent 1d95a87813adea377d956a89ebe7de9800cd9447 util: avoid a leaked file descriptor in `util.makelock()` exceptional case diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -2201,8 +2201,10 @@ def makelock(info, pathname): flags = os.O_CREAT | os.O_WRONLY | os.O_EXCL | getattr(os, 'O_BINARY', 0) ld = os.open(pathname, flags) - os.write(ld, info) - os.close(ld) + try: + os.write(ld, info) + finally: + os.close(ld) def readlock(pathname: bytes) -> bytes: