title: How a corrupted double linked list error is detected in malloc?
body: <p>I don't understand a condition for gettint the error - corrupted double-linked list (not small) - </p>
  
  <p>There is a point in the program where it crashes due to corrupted double-linked list (not small). </p>
  
  <p>At this moment, I don't want to know why it crashed, but I want to know how this conditions work</p>
  
  <pre><code>if (__builtin_expect (P-&gt;fd_nextsize-&gt;bk_nextsize != P, 0) || __builtin_expect(P-&gt;bk_nextsize-&gt;fd_nextsize != P, 0))    
       malloc_printerr (check_action,"corrupted double-linked list (not small)", P, AV);              
  </code></pre>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>Maybe I am confused with the structure of the double linked list in the bins. </p>
  
  <p>At this moment, I understand the double linked list as this: </p>
  
  <pre><code>+-------------------&gt;+----------------+ &lt;---------+
  |                    |  fd_nextsize   |           |
  |                    |                |           |
  |                    |                |           |
  |                    +----------------+           |
  |                    |                |           |
  |                    |fd_nextsize     |           |
  |                    |                |           |
  |                    +----------------+           |
  |                    |                |           |
  |                    +bk_nextisize    |--------------------+
  |                    |                |           |        |
  |                    +----------------+           |        |
  |                                                 |        |
  |                                                 |        |
  |                                                 |        |
  |                                                 |        |
  |                     +---------------+           |        |
  |                     |  P            |           |        |
  |                     |               |           |        |
  |                     +---------------+           |        |
  |                     |               |           |        |
  |                     |fd_nextsize    +-----------+        |
  |                     |               |                    |
  |                     +---------------+                    |
  |                     |               |                    |
  |         +-----------+bk_nextsize    |                    |
  |         |           |               |                    |
  |         |           +---------------+                    |
  |         |                                                |
  |         |                                                |
  |         |                                                |
  |         +-----------&gt;+----------------+&lt;-----------------+
  |                      | bk_nextisize   |
  |                      |                |
  |                      |                |
  |                      +----------------+
  |                      |                |
  +----------------------+ fd_nextsize    |
                         |                |
                         +----------------+
                         |bk_nextsize     |
                         |                |
                         +----------------+
  
  </code></pre>
  
  <p>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.</p>