Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 51884: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 |
comparison
equal
deleted
inserted
replaced
51883:1d95a87813ad | 51884:f833ad92ee44 |
---|---|
2199 except AttributeError: # no symlink in os | 2199 except AttributeError: # no symlink in os |
2200 pass | 2200 pass |
2201 | 2201 |
2202 flags = os.O_CREAT | os.O_WRONLY | os.O_EXCL | getattr(os, 'O_BINARY', 0) | 2202 flags = os.O_CREAT | os.O_WRONLY | os.O_EXCL | getattr(os, 'O_BINARY', 0) |
2203 ld = os.open(pathname, flags) | 2203 ld = os.open(pathname, flags) |
2204 os.write(ld, info) | 2204 try: |
2205 os.close(ld) | 2205 os.write(ld, info) |
2206 finally: | |
2207 os.close(ld) | |
2206 | 2208 |
2207 | 2209 |
2208 def readlock(pathname: bytes) -> bytes: | 2210 def readlock(pathname: bytes) -> bytes: |
2209 try: | 2211 try: |
2210 return readlink(pathname) | 2212 return readlink(pathname) |