My function is as follows:
void Insert_ldb(int t){
struct node_ldb *temp_ldb1,*lastnode_ldb;
temp_ldb1=root_ldb[t];
while(temp_ldb1->next!=NULL)
temp_ldb1=temp_ldb1->next;
if(temp_ldb1->next==NULL){
lastnode_ldb=malloc(sizeof(*lastnode_ldb));//error appears at this line
temp_ldb1->next=lastnode_ldb;
}
}
and the struct node_ldb is defined as:
struct node_ldb{
int sno;
int *lvar;
int *object;
struct node_ldb *next;
};
On compiling no error appears, but on executing it terminates with the message:
malloc.c:3096: sYSMALLOc: Assertion
(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)
failed. Aborted
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?