Re: segmentation fault in strcmp()
- From: James Kuyper <jameskuyper@xxxxxxxxxxx>
- Date: Wed, 17 Jun 2009 10:54:55 GMT
mohangupta13 wrote:
....
now i get an error like ****** free:invalid next size
(fast) .....********
at some different place. Though I am quite sure that the object being
freed at the point where this error occurs is surely allocated by
malloc and is not doubly freed ....as i can use gdb to print the
various fields using the pointer in question..(.after the crash using
backtrace)
Now can anyone please clear few doubts of mine:
1. What is the meaning of such an error like invalid next size(fast) /
invalid next size(normal) etc etc..
It means that the free() is trying to figure out the size of the next block of memory in the heap; information it needs in order to complete the process of freeing the memory you've asked it to release. Unfortunately, the piece of memory where it is looking for that information contains an invalid value. Since the place where it looks is determined in part by the pointer that you pass to free(), one possibility is that you're passing the wrong pointer to free(); another possibility is that the memory where that information was stored has become corrupted. There's several ways in which this can happen:
If char* p=malloc(N), executing an expression like "p[i] = expression" could cause such a problem if i<0 || i>=N.
If p is not a pointer returned by a call to malloc() (or calloc() or realloc()), then free(p) could cause this problem.
If p used to point into a block of memory allocated by malloc(), calloc(), or realloc(), but that memory has since been free()d, then free(p) could cause this problem. So could "p[i] = expression", regardless of the value of i.
2. Is it really occurring because of the call to free which i get
using backtrace or the actual cause may have been long bypassed
somewhere else and it ends up showing its side effects here.
While the problem is being detected in your call to free(), the actual defect that caused the problem may have occurred long before the call to free(), in some completely unrelated part of your program. This is what makes problems like this so hard to track down.
.
- References:
- segmentation fault in strcmp()
- From: mohangupta13
- Re: segmentation fault in strcmp()
- From: Lorenzo Beretta
- Re: segmentation fault in strcmp()
- From: Joachim Schmitz
- Re: segmentation fault in strcmp()
- From: Lorenzo Beretta
- Re: segmentation fault in strcmp()
- From: mohangupta13
- segmentation fault in strcmp()
- Prev by Date: Re: Question about array declarators
- Next by Date: Re: More optimisation
- Previous by thread: Re: segmentation fault in strcmp()
- Next by thread: Re: segmentation fault in strcmp()
- Index(es):
Relevant Pages
|