FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
Saikumar Mandaji ccbd282d5c fix(POSIX port): check pthread_key_create/pthread_setspecific return values
prvInitThreadKey() ignored pthread_key_create()'s return value, and
prvMarkAsFreeRTOSThread() ignored pthread_setspecific()'s return
value.

If pthread_setspecific() fails, the one-byte thread marker allocated
just before it is neither stored in TLS (so prvThreadKeyDestructor()
never runs for it, leaking the allocation) nor freed locally -- and
the thread is left unmarked, so prvIsFreeRTOSThread() silently
misclassifies it as not a FreeRTOS thread. The correctness impact
(thread identity) is larger than the one-byte leak itself.

Fix: check both return values. On pthread_setspecific() failure, free
the marker to avoid the leak, then call prvFatalError() -- the same
handling this port already uses for other unexpected pthread call
failures (pthread_create(), sigaction()). This function returns void,
so there is no way to propagate a failure to the caller; continuing
past a failed pthread_setspecific() would leave the thread silently
misclassified rather than failing loudly. Same treatment for
pthread_key_create(), since a failure there means every later
pthread_setspecific()/pthread_getspecific() call on xThreadKey is
operating on an invalid key.

Fixes #1447

Signed-off-by: Saikumar Mandaji <mandajisaikumar@gmail.com>
2026-07-18 19:20:34 +05:30
..
utils Mark mutex as robust to prevent deadlocks (#1233) 2025-01-29 07:27:30 +05:30
FreeRTOS-simulator-for-Linux.url Normalize line endings and whitespace in source files 2022-11-29 15:38:47 -08:00
port.c fix(POSIX port): check pthread_key_create/pthread_setspecific return values 2026-07-18 19:20:34 +05:30
portmacro.h Fix spelling typos (#1168) 2024-11-01 10:09:49 -07:00