changeset 51888:f833ad92ee44

util: avoid a leaked file descriptor in `util.makelock()` exceptional case
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 20 Sep 2024 00:20:24 -0400
parents 1d95a87813ad
children cbd01bf33802
files mercurial/util.py
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Fri Sep 20 00:04:09 2024 -0400
+++ b/mercurial/util.py	Fri Sep 20 00:20:24 2024 -0400
@@ -2201,8 +2201,10 @@
 
     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: