mjansson / rpmalloc

Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C
Other
2.16k stars 187 forks source link

possible bug in _memory_allocate at rpmalloc/rpmalloc.c:1322 #107

Closed gstvrmrlpz closed 5 years ago

gstvrmrlpz commented 5 years ago

A half finish lockfree stack implementation is triggering a bug in _memory_allocate. Code + exe + core in https://pccito.ugr.es/bug.tar.xz

mjansson commented 5 years ago

Considering it segfaults using the standard malloc I think the problem is in your code

./stack 
  n   compress
  1     966209
free(): double free detected in tcache 2
stack: stack.cc:32: unsigned int work(std::atomic<bool>&, stack&) [with stack = compress::stack<int>]: Assertion `s.pop() == 0x12345678' failed.
Aborted (core dumped)
gstvrmrlpz commented 5 years ago

my code is full of bugs but I thought a call to new aka _memory_allocate should always success while there is enough free memory...

mjansson commented 5 years ago

No, not when you have corrupted the memory heap with bad calls (like a double free)

mjansson commented 5 years ago

From the readme: "All entry points assume the passed values are valid, for example passing an invalid pointer to free would most likely result in a segmentation fault. The library does not try to guard against errors."