C/free(), and malloc error
Expert: Narendra - 7/13/2005
Question(Using GCC 3.2.3 under RH Enterprise Linux)
I have just re-written a function. All of a sudden, my program now sometimes crashes in a completely different function when I try to free up some allocated memory. On debugging, I get the following error message:
Program received signal SIGSEGV, Segmentation fault.
0x008a730e in malloc_consolidate () from /lib/tls/libc.so.6
I know that this is related to my new function, because if I remove it, the program does not crash. I have used mtrace() to deduce that there are no memory leaks. I have found on the internet that some errors can be caused by freeing the same memory twice, but having double-checked my new function, I have not done this.
Can you offer any suggestions for what might be causing this error?
AnswerSo, according to you your program is correct and computer may be doing something wrong!!?
Without looking at your code, how can I give any suggestion!?
You have already checked that, you are not freeing a NULL pointer.
You have already checked that, you are not trying to free second time.
The only thing left is to check the addresses.
Check the address when you did malloc().
Check the address before doing free().
If both are not same, then that can be the cause of crash. That means you have changed the pointer at some place in the new function.