Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weird SIGABORT on malloc/calloc call

running my program with gdb I get this:

fem.o: 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.

Program received signal SIGABRT, Aborted. 0xb7fe1424 in __kernel_vsyscall ()

I found that this error arises after this code:

problem->y0 = (double *)calloc(n_tot, sizeof(double));

problem is a structure which has double *y0 as member.

Previously in the function, I do this

problem = (fem_problem *)calloc(1, sizeof(fem_problem));

and I don't get any error neither problem == NULL.

some suggestion?

ADD:

I already checked the content of n_tot, it has the right number

like image 516
the_candyman Avatar asked Nov 27 '25 09:11

the_candyman


1 Answers

The assertion is telling you that the heap internal data structures are corrupt, probably due to your writing outside the bounds of an allocated block at some point. Try running with valgrind to see if it can tell you where you're going wrong.

like image 164
Chris Dodd Avatar answered Nov 29 '25 22:11

Chris Dodd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!