MallocAllocator does not check for allocation failure

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

Maintainers usually reply within 2 days

@umrndem is already working on this.

Since Dec 5, 2026.

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, devtools

Research direction

Read include/tscore/Allocator.h, especially MallocAllocator::alloc_void() at lines 137–148 and ClassAllocator::alloc() at lines 343–345. Compare the allocation failure handling with the ats_malloc and ats_memalign path in src/tscore/ink_queue.cc around line 245. Done means allocation failure produces a clear out-of-memory failure instead of continuing with a null pointer; the issue does not name a test.

Written by the indexing model from the issue text.

Description

Bug Core Good First Issue

With ENABLE_MALLOC_ALLOCATOR, Allocator is MallocAllocator (Allocator.h#L315-L325). MallocAllocator::alloc_void() returns the result of malloc or aligned_alloc without checking it, and calls madvise on it first (Allocator.h#L137-L148). ClassAllocator::alloc() then placement-news the object at the returned pointer (Allocator.h#L343-L345).

On allocation failure, the object is therefore constructed at nullptr, which is undefined behavior and normally a crash at some later, unrelated-looking point. The default freelist allocator gets its memory through ats_malloc/ats_memalign (ink_queue.cc#L245), which abort with a clear out-of-memory message. The malloc build should behave the same way.

Suggested fix: allocate through ats_malloc/ats_memalign in MallocAllocator::alloc_void(), or check the result and abort with an out-of-memory error.


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.