aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zachary.medico@sony.com>2019-02-19 16:17:26 -0800
committerZac Medico <zmedico@gentoo.org>2019-02-19 16:38:09 -0800
commit6b95678e23bf2b68bfd27d7c50777efc38fd4ea3 (patch)
tree9421eb2639886f51d007b41a1141543690d0c2b1
parentlockfile: use loop instead of recursion (diff)
downloadportage-6b95678e23bf2b68bfd27d7c50777efc38fd4ea3.tar.gz
portage-6b95678e23bf2b68bfd27d7c50777efc38fd4ea3.tar.bz2
portage-6b95678e23bf2b68bfd27d7c50777efc38fd4ea3.zip
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@gentoo.org>
-rw-r--r--lib/portage/locks.py17
1 files 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: