Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
45717:755214a84b9d | 45718:87c35b5a14eb |
---|---|
762 # use relative path instead of full path at bind() if possible, since | 762 # use relative path instead of full path at bind() if possible, since |
763 # AF_UNIX path has very small length limit (107 chars) on common | 763 # AF_UNIX path has very small length limit (107 chars) on common |
764 # platforms (see sys/un.h) | 764 # platforms (see sys/un.h) |
765 dirname, basename = os.path.split(path) | 765 dirname, basename = os.path.split(path) |
766 bakwdfd = None | 766 bakwdfd = None |
767 if dirname: | 767 |
768 bakwdfd = os.open(b'.', os.O_DIRECTORY) | 768 try: |
769 os.chdir(dirname) | 769 if dirname: |
770 sock.bind(basename) | 770 bakwdfd = os.open(b'.', os.O_DIRECTORY) |
771 if bakwdfd: | 771 os.chdir(dirname) |
772 os.fchdir(bakwdfd) | 772 sock.bind(basename) |
773 os.close(bakwdfd) | 773 if bakwdfd: |
774 os.fchdir(bakwdfd) | |
775 finally: | |
776 if bakwdfd: | |
777 os.close(bakwdfd) |