Skip to content

fix(stl): ThreadLocalReal::access() dereferences null when pthread_key_create/setspecific fails #5310

Closed

Description

@zackees

Problem

In src/fl/stl/thread_local.h, ThreadLocalReal<T>::access() dereferences a null pointer if pthread_key_create fails (constructor) or if pthread_setspecific / the per-thread allocation fails on first access. Pre-existing; noticed while fixing #5304 (PR #5309).

Proposed solution

  • Check the return code of pthread_key_create; record a "key invalid" state.
  • In access(), if the key is invalid or pthread_setspecific fails (or allocation returns null), fall back to a single shared fallback slot (or FL_ASSERT + fallback) rather than dereferencing null; free the allocated storage when setspecific fails.
  • Keep the fast path unchanged; add a unit test if failure can be injected cheaply (otherwise document why not).

Activity

  1. added
    type: bug
    on Nov 20, 2026
  2. added
    sanitized
    on Nov 20, 2026
  3. moved this from Triage to Done in FastLED Trackeron Nov 20, 2026
  4. added a commit that references this issue on Nov 20, 2026
    eab643f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitizedtype: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions