commit: 6b95678e23bf2b68bfd27d7c50777efc38fd4ea3 Author: Zac Medico <zachary.medico <AT> sony <DOT> com> AuthorDate: Wed Feb 20 00:17:26 2019 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Wed Feb 20 00:38:09 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=6b95678e
lockfile: do not leak file descriptor after _lockfile_was_removed exception Bug: https://bugs.gentoo.org/678278 Copyright: Sony Interactive Entertainment Inc. Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> lib/portage/locks.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/portage/locks.py b/lib/portage/locks.py index fff27e55e..609c8b2dc 100644 --- a/lib/portage/locks.py +++ b/lib/portage/locks.py @@ -299,11 +299,18 @@ def _lockfile_iteration(mypath, wantnewlockfile=False, unlinkfile=False, raise - if isinstance(lockfilename, basestring) and \ - myfd != HARDLINK_FD and unlinkfile and _lockfile_was_removed(myfd, lockfilename): - # Removed by previous lock holder... Caller will retry... - os.close(myfd) - return None + if isinstance(lockfilename, basestring) and myfd != HARDLINK_FD and unlinkfile: + try: + removed = _lockfile_was_removed(myfd, lockfilename) + except Exception: + # Do not leak the file descriptor here. + os.close(myfd) + raise + else: + if removed: + # Removed by previous lock holder... Caller will retry... + os.close(myfd) + return None if myfd != HARDLINK_FD:
