[BUG] POSIX (GCC) port: thread marker leaked and thread mis-identified when `pthread_setspecific()` fails
Maintainer thường phản hồi trong vòng 3 ngày
@94xhn đang làm issue này rồi.
Từ ngày 12/7/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- c
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
The relevant code is in portable/ThirdParty/GCC/Posix/port.c: prvMarkAsFreeRTOSThread(), prvThreadKeyDestructor() and prvIsFreeRTOSThread(). Before starting, read the two linked open pull requests (#1452 and #1453) to see what they already change, since the work is under way. Done means the pthread_setspecific() failure path frees the marker and applies a defined failure policy, and pthread_key_create() status is checked.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In portable/ThirdParty/GCC/Posix/port.c, prvMarkAsFreeRTOSThread() allocates a one-byte thread marker and stores it in thread-specific storage via pthread_setspecific(), but ignores the return value. If pthread_setspecific() fails, the marker is neither stored (so the TLS destructor never frees it) nor freed locally, leaking it — and the thread is left unmarked, so prvIsFreeRTOSThread() misclassifies it.
Affected code
portable/ThirdParty/GCC/Posix/port.c:
static void prvThreadKeyDestructor( void * pvData )
{
free( pvData );
}
/* ... key created once ... */
pthread_key_create( &xThreadKey, prvThreadKeyDestructor ); /* return ignored */
/* ... per FreeRTOS pthread ... */
uint8_t * pucThreadData = NULL;
pucThreadData = malloc( 1 );
configASSERT( pucThreadData != NULL );
*pucThreadData = 1;
pthread_setspecific( xThreadKey, pucThreadData ); /* return ignored */
Problem
On the success path this is not a leak: ownership of the marker transfers to the
pthread TLS, and prvThreadKeyDestructor() frees it when the thread exits or is
cancelled.
On the failure path (pthread_setspecific() returns non-zero, e.g. EINVAL for
an invalid key or ENOMEM for insufficient resources):
- The pointer is not stored in thread-specific storage.
- The TLS destructor never receives it.
- The local variable goes out of scope on return.
- The one-byte allocation leaks.
prvIsFreeRTOSThread()will incorrectly report that this thread is not a
FreeRTOS thread.
The correctness impact (thread identity) is arguably larger than the one-byte
leak itself.
Severity
Low as a leak: one byte plus allocator metadata per failure, only on an error
path that typically indicates the host is already resource-constrained. Worth
fixing together with the related robustness gaps below.
Suggested fix
int xResult;
xResult = pthread_setspecific( xThreadKey, pucThreadData );
if( xResult != 0 )
{
free( pucThreadData );
configASSERT( xResult == 0 );
}
Because the function returns void, if configASSERT is compiled out a failure
policy is still needed — terminate the pthread, invoke a port-specific fatal
handler, or change the function to return status so the caller can abort
initialization. Freeing and continuing avoids the leak but leaves the thread
unmarked, which may lead to incorrect later control flow.
Related robustness issues (same area)
configASSERT( pucThreadData != NULL )is followed by an unconditional
*pucThreadData = 1;. WithconfigASSERTcompiled out andmalloc()failing,
this is a NULL dereference.pthread_key_create()'s return value is also ignored; if key creation fails,
pthread_setspecific()will subsequently fail. A complete fix should save and
check the key initialization status.
- Ngôn ngữ chính
- C
- Star
- 4.6k
- Fork
- 1.6k
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FreeRTOS/FreeRTOS-Kernel
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] Release asset FreeRTOS-KernelV11.3.2.zip has the files of main, not of the tag V11.3.2Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] event_wait_timed can't return falseCó thể đã có người làm @TedLyngmo đã nhận 39 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của FreeRTOS/FreeRTOS-Kernel
Issue tương tự
-
RecompLauncher supportĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
shinyquagsire23/OpenJKDF2#540 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Life-Framework/Life-Framework#5939 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
autoconf failes to find libsodium even when present due to implicit function declarationCó thể đã có người làm @coderjoe đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 13 ngày
-
SessionInterfaceHandler is throwing a deprecation notice as a warning instead of a deprecationĐang mởBug Status: Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement_package: a site operand of another JSON type raises TypeError, not a named refusalĐang mởbug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Jstar269/nakagawa-recomp#3521 ·
Maintainer thường phản hồi trong vòng 1 ngày