From 5746943f50d107282ae1c7fda290e983f53b3c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Mon, 6 Jul 2020 12:26:15 -0300 Subject: [PATCH] AP_HAL_Linux: Use pthread_self in place of _ctx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid aproblem where _ctx is initialized in a race condition. Signed-off-by: Patrick José Pereira --- libraries/AP_HAL_Linux/Thread.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_Linux/Thread.cpp b/libraries/AP_HAL_Linux/Thread.cpp index a9659e84cb..806fb8c5fa 100644 --- a/libraries/AP_HAL_Linux/Thread.cpp +++ b/libraries/AP_HAL_Linux/Thread.cpp @@ -85,7 +85,9 @@ void Thread::_poison_stack() void *stackp; uint32_t *p, *curr, *begin, *end; - if (pthread_getattr_np(_ctx, &attr) != 0 || + // `pthread_self` should be used here since _ctx could be not initialized + // in a race condition. + if (pthread_getattr_np(pthread_self(), &attr) != 0 || pthread_attr_getstack(&attr, &stackp, &stack_size) != 0 || pthread_attr_getguardsize(&attr, &guard_size) != 0) { return;