I don't understand a condition for gettint the error - corrupted double-linked list (not small) -
There is a point in the program where it crashes due to corrupted double-linked list (not small).
At this moment, I don't want to know why it crashed, but I want to know how this conditions work
if (__builtin_expect (P->fd_nextsize->bk_nextsize != P, 0) || __builtin_expect(P->bk_nextsize->fd_nextsize != P, 0))
malloc_printerr (check_action,"corrupted double-linked list (not small)", P, AV);
Here we can see that the error double-linked list is observed when the P->fd_nextsize->bk_nextsize != P is not accomplished or P->bk_nextsize->fd_nextsize is not accomplished.
But my main problem is that I can't explain how this part of code - P->fd_nextsize->bk_nextsize - expects to be P. I am expecting that P->fd_nextsize->bk_nextsize is P->bk_nextsize.
Maybe I am confused with the structure of the double linked list in the bins.
At this moment, I understand the double linked list as this:
+------------------->+----------------+ <---------+
| | fd_nextsize | |
| | | |
| | | |
| +----------------+ |
| | | |
| |fd_nextsize | |
| | | |
| +----------------+ |
| | | |
| +bk_nextisize |--------------------+
| | | | |
| +----------------+ | |
| | |
| | |
| | |
| | |
| +---------------+ | |
| | P | | |
| | | | |
| +---------------+ | |
| | | | |
| |fd_nextsize +-----------+ |
| | | |
| +---------------+ |
| | | |
| +-----------+bk_nextsize | |
| | | | |
| | +---------------+ |
| | |
| | |
| | |
| +----------->+----------------+<-----------------+
| | bk_nextisize |
| | |
| | |
| +----------------+
| | |
+----------------------+ fd_nextsize |
| |
+----------------+
|bk_nextsize |
| |
+----------------+
So, if I am incorrect about my understanding of the double linked lists in the bins (Important information, according to the code and also due to the fact that we are using fd_nextsize and bk_nextsize this chunk is not in the smallbin) please correct me. Since at this moment, this condition does not make any sense to me.