Mercurial > hg
diff mercurial/posix.py @ 45718:87c35b5a14eb
posix: avoid a leaked file descriptor in a unix domain socket exception case
Differential Revision: https://phab.mercurial-scm.org/D9206
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 13 Oct 2020 16:44:57 -0400 |
parents | 755214a84b9d |
children | 89a2afe31e82 |
line wrap: on
line diff
--- a/mercurial/posix.py Tue Oct 13 16:41:01 2020 -0400 +++ b/mercurial/posix.py Tue Oct 13 16:44:57 2020 -0400 @@ -764,10 +764,14 @@ # platforms (see sys/un.h) dirname, basename = os.path.split(path) bakwdfd = None - if dirname: - bakwdfd = os.open(b'.', os.O_DIRECTORY) - os.chdir(dirname) - sock.bind(basename) - if bakwdfd: - os.fchdir(bakwdfd) - os.close(bakwdfd) + + try: + if dirname: + bakwdfd = os.open(b'.', os.O_DIRECTORY) + os.chdir(dirname) + sock.bind(basename) + if bakwdfd: + os.fchdir(bakwdfd) + finally: + if bakwdfd: + os.close(bakwdfd)