free() fails in vc 6 debug mode
-
while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...
-
while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...
You would be well-served to narrow the code down to just the statements necessary required to produce the problem. As it stands, it could be one of the other allocations, or the code that is using
list
,slist
, ornodes
.leowwl wrote:
list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int));
What is
list
,slist
, ande
? Why are the return values from the two calls tocalloc()
not cast to anint*
?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...
-
You would be well-served to narrow the code down to just the statements necessary required to produce the problem. As it stands, it could be one of the other allocations, or the code that is using
list
,slist
, ornodes
.leowwl wrote:
list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int));
What is
list
,slist
, ande
? Why are the return values from the two calls tocalloc()
not cast to anint*
?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
DavidCrow wrote:
Why are the return values from the two calls to calloc() not cast to an int*?
The calloc function returns a void* pointing to newly allocated data. It means that you only need to cast if the compiler complains. regards hint_54
hint_54 wrote:
The calloc function returns a void* pointing to newly allocated data.
I'm aware of what it does.
hint_54 wrote:
It means that you only need to cast if the compiler complains.
I don't subscribe to that philosophy. As it stands, if
list
is anint*
, a compiler error will result unless a cast is provided. I suspect thatlist
is avoid*
.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
hint_54 wrote:
The calloc function returns a void* pointing to newly allocated data.
I'm aware of what it does.
hint_54 wrote:
It means that you only need to cast if the compiler complains.
I don't subscribe to that philosophy. As it stands, if
list
is anint*
, a compiler error will result unless a cast is provided. I suspect thatlist
is avoid*
.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
DavidCrow wrote:
a compiler error will result unless a cast is provided
Depends on the compiler you are using. Borland compilers (at least the older ones, don't know about the newest) would only issue a warning. You could simply ignore. I don't know wich compiler he is using, so I cant tell. regards hint_54 -- modified at 13:38 Thursday 6th April, 2006 Ups... I'm sorry, you are right. I didnt notice the title :-O regards
-
DavidCrow wrote:
a compiler error will result unless a cast is provided
Depends on the compiler you are using. Borland compilers (at least the older ones, don't know about the newest) would only issue a warning. You could simply ignore. I don't know wich compiler he is using, so I cant tell. regards hint_54 -- modified at 13:38 Thursday 6th April, 2006 Ups... I'm sorry, you are right. I didnt notice the title :-O regards
This is a Microsoft VC++ forum and any answers given will/should reflect such.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
This is a Microsoft VC++ forum and any answers given will/should reflect such.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...
It happens when you allocate too small heap to keep data. Code below causes such error:
char *buf = (char *)malloc(sizeof(char)); // just 1 byte allocated
strcpy(buf, "longlonglong string. You allocated only one byte, just one char, how you copy so many chars in place where room is only for one char?");
free(buf);compiler just inform you that your data are not allocated right way and may be corrupted. -- modified at 18:37 Thursday 6th April, 2006
-
while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...
-
while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...
The first one means that the heap manager does not think that you are freeing a pointer to a valid block of memory. The second usually means that you ran off the end of a block of allocated memory. If the two errors happen on blocks of memory that were allocated back-to-back, I would think that you walked off the end of one block stepping on the next. Check any code that copies data into the memory referenced by those pointers to make sure you are keeping the correct size constraints. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)