diff --git a/lib/locking.py b/lib/locking.py
index 014b378509b01057078b579858ad38e84887d530..cf7af34993d4dee6e9b0486b32da9341b4e4c81d 100644
--- a/lib/locking.py
+++ b/lib/locking.py
@@ -1050,8 +1050,8 @@ class LockSet:
       self.__owners[threading.currentThread()].remove(name)
 
     # Only remove the key if we don't hold the set-lock as well
-    if (not self.__lock.is_owned() and
-        not self.__owners[threading.currentThread()]):
+    if not (self.__lock.is_owned() or
+            self.__owners[threading.currentThread()]):
       del self.__owners[threading.currentThread()]
 
   def list_owned(self):