title: malloc.c:3096: SYSMALLOC: Assertion failed
body: <p>My function is as follows: </p>
  
  <pre><code>void Insert_ldb(int t){
      struct node_ldb *temp_ldb1,*lastnode_ldb;
      temp_ldb1=root_ldb[t];
      while(temp_ldb1-&gt;next!=NULL)
          temp_ldb1=temp_ldb1-&gt;next;
      if(temp_ldb1-&gt;next==NULL){
           lastnode_ldb=malloc(sizeof(*lastnode_ldb));//error appears at this line
           temp_ldb1-&gt;next=lastnode_ldb;
      }
  }
  </code></pre>
  
  <p>and the struct node_ldb is defined as:</p>
  
  <pre><code>struct node_ldb{
      int sno;
      int *lvar;
      int *object;
      struct node_ldb *next;
  };
  </code></pre>
  
  <p>On compiling no error appears, but on executing it terminates with the message: </p>
  
  <blockquote>
    <p>malloc.c:3096: sYSMALLOc: Assertion <code>(old_top == (((mbinptr) (((char *) &amp;((av)-&gt;bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) &amp;&amp; old_size == 0) || ((unsigned long) (old_size) &gt;= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) &amp; ~((2 * (sizeof(size_t))) - 1))) &amp;&amp; ((old_top)-&gt;size &amp; 0x1) &amp;&amp; ((unsigned long)old_end &amp; pagemask) == 0)</code> failed.
    Aborted</p>
  </blockquote>
  
  <p>The weird part is that the same function executes successfully many times prior to termination. So is it possible that the error happened somewhere else? Because even valgrind does not show any error for the same. What could be the problem?</p>