2

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

the_candyman
  • 1,563
  • 4
  • 22
  • 36
  • Please format your code by indenting 4 spaces (use the `{}` button). The preview the question before submitting. – kennytm Apr 04 '11 at 15:28

2 Answers2

8

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.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
4

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.

Lindydancer
  • 25,428
  • 4
  • 49
  • 68
  • Checked for n_tot before calloc call, it contains the right number. I don't undestand 2nd point :( – the_candyman Apr 04 '11 at 15:32
  • If you have allocated, say, 100 bytes, and you write to a location that is 150 bytes from the start (or in front of it, but that is less likely) you may have overwritten data that was used for other things. – Lindydancer Apr 04 '11 at 15:37