THREAD_ALLOC dereferences a null thread while THREAD_FREE falls back to the global allocator

Open Beginner friendly
#14,217 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start with the THREAD_ALLOC, SAFE_THREAD_ALLOC, and THREAD_FREE macros in include/iocore/eventsystem/ProxyAllocator.h (lines 87–110). Compare their null-thread behavior and check the callers named in IOBuffer.cc, InkAPI.cc, and cripts/unit_tests/main.cc. Done means allocation from an unregistered thread no longer dereferences a null pointer, with the intended fallback or diagnostic covered by an appropriate test.

Written by the indexing model from the issue text.

Description

Bug Event System Threads

THREAD_ALLOC and THREAD_ALLOC_INIT expand to thread_alloc(::_a, _t->_a, ...) and dereference the thread pointer unconditionally (ProxyAllocator.h#L87-L88). The matching THREAD_FREE checks for a null thread and frees to the global allocator instead (ProxyAllocator.h#L109-L110), and SAFE_THREAD_ALLOC does the same for allocation (ProxyAllocator.h#L89).

Most callers pass this_thread() or this_ethread(), which is null on any OS thread not registered with the event system. Examples include new_MIOBuffer / new_IOBufferBlock (IOBuffer.cc#L171, IOBuffer.cc#L723), TSContCreate() (InkAPI.cc#L3844) and TSVConnCreate() (InkAPI.cc#L6426). Allocating from an unregistered thread crashes, but freeing the same object there works. Setting cmd_disable_pfreelist doesn't help either, because the macro still evaluates _t->_a. The cripts unit test has to register a fake EThread on main for this reason (cripts/unit_tests/main.cc#L41-L45).

Suggested fix: give THREAD_ALLOC the same null fallback as THREAD_FREE (i.e. make it SAFE_THREAD_ALLOC), or turn the null case into an ink_release_assert with a message, so a plugin calling these APIs from its own thread gets a diagnosable error rather than a segfault.


generated with Claude Opus 5.5 by Josiah VanderZee

Dominant language
C++
Stars
2k
Forks
903
Avg merge
4d 4h
Merged PRs (30d)
135

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/trafficserver

All issues in apache/trafficserver

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.