I was writing a simple count inversion program using merge sort. While allocating the memory at runtime using calloc I got the following error:
a.out: malloc.c:2372: 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 (core dumped)
with this code:
int *temp = (int*)calloc(1, sizeof(int) * (l1+l2)) ;
while using malloc instead of calloc works fine.On googling I found it a kind of memory corruption issue but didn't get it clearly