Note that there are some explanatory texts on larger screens.

plurals
  1. POLinked list insertion results in sysmalloc assertion error
    primarykey
    data
    text
    <p>I have written a code to add a new member to a list . Its working fine when I take add two members. However, as soon as I add third and compile and run the code gives me an error. The code and error are as follow:</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; struct list_no { struct list_no *prev,*nest; struct linked_list *fnl; int seq_no; }; static int counter = 0; struct list_no *lists,*first; int add_list() { struct list_no *temp; counter++; if(lists == '\0') { lists = (struct list_no *)malloc(sizeof(struct list_no)); lists-&gt;prev = '\0'; lists-&gt;nest = '\0'; lists-&gt;fnl = '\0'; lists-&gt;seq_no = 1; first = lists; } else { temp = lists; lists-&gt;nest = (struct list_no *)malloc(sizeof(struct linked_list)); lists = lists-&gt;nest; lists-&gt;fnl = '\0'; lists-&gt;prev = temp; lists-&gt;nest = NULL; lists-&gt;seq_no = counter; } return 0; } int main() { int i=0,lcount; int i=0,lcount; char ch = 'y'; first = '\0'; lists = first; int w; while(i != 3) { add_list(); printf("\n the val ::%d\n",lists-&gt;seq_no); i++; } return 0; } </code></pre> <p>the error message coming after ./a.out is :</p> <pre><code>the val ::1 the val ::2 a.out: malloc.c:3097: sYSMALLOc: Assertion `(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)' failed. Aborted </code></pre> <p>Why its not able to add third member?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload