Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glibc detect smallbin linked list corrupted

I am trying to run a function repeatedly in a large loop but I get an error after 2 or 3 iterations but if I start from the point it gave an error it works fine but again stops after 3 4 iteration. It might be a memory problem. As the function is quite large I am not sure where exactly there is a memory leakage. Is there anyway I can free the variables after each iteration or something that can solve this problem. Or as it is a linked list memory problem free all the linked list or something?What can be the solution? The problrm does not happen if I run the function once so I think it is because I am calling the function repeatedly in a loop. Is there any way to solve this problem?

The error is

**glibc detected:.....malloc():smallbin double linked list corrupted: 0x000000000 1d404c0 ***
like image 559
user1583647 Avatar asked Oct 23 '13 06:10

user1583647


Video Answer


1 Answers

The library is telling you that the memory metadata is corrupt. That won't happen by mere memory leak, you had to write to invalid pointer. Either you wrote to index out of bounds or you wrote to pointer after it was freed.

The easiest way to debug this kind of issue is using valgrind. It only works under Linux, but you seem to be using that already. It is rather slow, because it single-steps the program and checks every memory-accessing instruction, but it can catch invalid memory access and also use of uninitialized variables and memory leaks very reliably.

There is also duma (detect unintended memory access) library. It can also be made to work on other platforms and is a bit faster, but it uses much more memory.

And there is gcc's own mudflap that can be activated by specific compiler options. That one should work on most gcc targets, but I am not sure how complete the C++ support is.

Update (11/2018): mudflap is mostly superseded by Google Sanitizers, which are part of Clang.

like image 156
Jan Hudec Avatar answered Nov 06 '22 21:11

Jan Hudec