gperftools / gperftools/gperftools

debug allocator may crash on OOM (was: tcmalloc failure memset(ptr, 0, sizeof(Object) + num*sizeof(T));)

Open
#711 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

(gdb) p ptr
$1 = (void *) 0x0
(gdb) f 0
#0 0x00007f586e642a33 in New<AddressMap::Entry> (num=64, this=0x25c8000, this=0x25c8000)

at src/addressmap-inl.h:259

259 memset(ptr, 0, sizeof(Object) + num_sizeof(T));
(gdb) l
254 // Allocates a zeroed array of T with length "num". Also inserts
255 // the allocated block into a linked list so it can be deallocated
256 // when we are all done.
257 template T_ New(int num) {
258 void* ptr = (alloc)(sizeof(Object) + num_sizeof(T));
259 memset(ptr, 0, sizeof(Object) + num_sizeof(T));
260 Object_ obj = reinterpret_cast<Object*>(ptr);
261 obj->next = allocated_;
262 allocated_ = obj;
263 return reinterpret_cast<T*>(reinterpret_cast<Object*>(ptr) + 1);
(gdb) bt
#0 0x00007f586e642a33 in New<AddressMap::Entry> (num=64, this=0x25c8000, this=0x25c8000)

at src/addressmap-inl.h:259

#1 AddressMap::Insert (this=0x25c8000, key=key@entry=0x28f606e0, value=value@entry=-21308287)

at src/addressmap-inl.h:324

#2 0x00007f586e642c56 in Initialize (type=-21308287, size=512, this=)

at src/debugallocation.cc:381

#3 Allocate (type=-21308287, size=512) at src/debugallocation.cc:535
#4 DebugAllocate (type=-21308287, size=512) at src/debugallocation.cc:987
#5 debug_cpp_alloc (size=512, new_type=-21308287, nothrow=) at src/debugallocation.cc:1106
#6 0x00007f586e65ea25 in tc_new (size=size@entry=512) at src/debugallocation.cc:1215
#7 0x00000000004107fa in allocate (__n=64, this=)

at /usr/include/c++/4.8.2/ext/new_allocator.h:104

#8 _M_allocate_node (this=) at /usr/include/c++/4.8.2/bits/stl_deque.h:533
#9 _M_create_nodes (this=0x5761ce0, __nfinish=0x286422d0, __nstart=0x286422c8)

at /usr/include/c++/4.8.2/bits/stl_deque.h:627

#10 std::_Deque_base<ctx_t*, std::allocator<ctx_t*> >::_M_initialize_map (this=this@entry=0x5761ce0,

__num_elements=__num_elements@entry=0) at /usr/include/c++/4.8.2/bits/stl_deque.h:601

so the alloc seemed to have returned nul and tcmalloc does not seem to be able to handle it.

so two things: OOM killer did not kill the process; alloc seemed to have failed with null ptr.

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start at src/addressmap-inl.h:257-262 and trace the allocation path through src/debugallocation.cc:381, 535, 987, and 1106. Reproduce or inspect the null allocation path and establish the intended out-of-memory behavior; done means allocation failure no longer reaches memset with a null pointer.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.