diff mbox series

utils: lock_timeout_nocheck() ensure `l` is initialized

Message ID 20250411210146.6741-1-mark.asselstine@windriver.com
State New
Headers show
Series utils: lock_timeout_nocheck() ensure `l` is initialized | expand

Commit Message

Mark Asselstine April 11, 2025, 9:01 p.m. UTC
lock_timeout_nocheck() can be interrupted immediately after enterring
the try-block and prior to initializing 'l', for example with a
ctrl-C, the code in finally will still be run and the 'if l' will
fail. Initialize 'l' as False to avoid this possiblity.

Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
---
 lib/bb/utils.py | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 5486f9599..a1e093925 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -1898,6 +1898,7 @@  def lock_timeout(lock):
 # A version of lock_timeout without the check that the lock was locked and a shorter timeout
 @contextmanager
 def lock_timeout_nocheck(lock):
+    l = False
     try:
         s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals())
         l = lock.acquire(timeout=10)