Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/
Date: Wed, 20 Feb 2019 00:58:12
Message-Id: 1550623089.6b95678e23bf2b68bfd27d7c50777efc38fd4ea3.zmedico@gentoo
1 commit: 6b95678e23bf2b68bfd27d7c50777efc38fd4ea3
2 Author: Zac Medico <zachary.medico <AT> sony <DOT> com>
3 AuthorDate: Wed Feb 20 00:17:26 2019 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 20 00:38:09 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=6b95678e
7
8 lockfile: do not leak file descriptor after _lockfile_was_removed exception
9
10 Bug: https://bugs.gentoo.org/678278
11 Copyright: Sony Interactive Entertainment Inc.
12 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
13
14 lib/portage/locks.py | 17 ++++++++++++-----
15 1 file changed, 12 insertions(+), 5 deletions(-)
16
17 diff --git a/lib/portage/locks.py b/lib/portage/locks.py
18 index fff27e55e..609c8b2dc 100644
19 --- a/lib/portage/locks.py
20 +++ b/lib/portage/locks.py
21 @@ -299,11 +299,18 @@ def _lockfile_iteration(mypath, wantnewlockfile=False, unlinkfile=False,
22 raise
23
24
25 - if isinstance(lockfilename, basestring) and \
26 - myfd != HARDLINK_FD and unlinkfile and _lockfile_was_removed(myfd, lockfilename):
27 - # Removed by previous lock holder... Caller will retry...
28 - os.close(myfd)
29 - return None
30 + if isinstance(lockfilename, basestring) and myfd != HARDLINK_FD and unlinkfile:
31 + try:
32 + removed = _lockfile_was_removed(myfd, lockfilename)
33 + except Exception:
34 + # Do not leak the file descriptor here.
35 + os.close(myfd)
36 + raise
37 + else:
38 + if removed:
39 + # Removed by previous lock holder... Caller will retry...
40 + os.close(myfd)
41 + return None
42
43 if myfd != HARDLINK_FD: