2
votes

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

2
Please format your code by indenting 4 spaces (use the {} button). The preview the question before submitting. - kennytm

2 Answers

8
votes

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.

4
votes

There could be any number of problems, for example:

  • The value of n_tot could be garbage.

  • You have written outside of an allocated block, and in doing so you have destroyed data structures used to maintain the heap.