free halts when used malloc 
Author Message
 free halts when used malloc

I'm getting a crash when I use free on a char pointer after I've malloc it.

I malloc my char pointer so many bytes, then go on and use it in my
function, then when I free the char pointer, she comes down crashing on me.
I have to free it because I'm starting the loop again. All this is done in
the same function.

Appreciate any ideas why this would happen and what would I do if I can use
free?

Thanks,
Jt



Sun, 27 Mar 2005 09:06:25 GMT  
 free halts when used malloc


Quote:
> I'm getting a crash when I use free on a char pointer after I've malloc it.

> I malloc my char pointer so many bytes, then go on and use it in my
> function, then when I free the char pointer, she comes down crashing on me.
> I have to free it because I'm starting the loop again. All this is done in
> the same function.

> Appreciate any ideas why this would happen and what would I do if I can use
> free?

It happens because some of the data structures
maintained by the allocator (in this case, the
malloc, calloc, realloc and free functions) are
being corrupted by inappropriate writes.  This
is commonly due to bad code overwriting the
allocated block(s).  Sometimes it happens due
to writing through invalid pointers or using
a bad index off of an allocation pointer.

If you use malloc/calloc, you must either use
free or suffer a leak.  You should have no
trouble using free once you cure the problem
of improper alteration of the allocator's data.

--
-Larry Brasfield
(address munged, s/sn/h/ to reply)



Sun, 27 Mar 2005 09:51:16 GMT  
 free halts when used malloc

Quote:

> I'm getting a crash when I use free on a char pointer after I've malloc it.

> I malloc my char pointer so many bytes, then go on and use it in my
> function, then when I free the char pointer, she comes down crashing on me.
> I have to free it because I'm starting the loop again. All this is done in
> the same function.

> Appreciate any ideas why this would happen and what would I do if I can use
> free?

> Thanks,
> Jt

Start commenting out things - any things.  A variety of pointer errors
with any pointer at all could corrupt the heap, but such corruption is
generally not discovered until the next call to malloc/free.  IOW, it is
not necessarily related to the pointer you think it is.

--
Scott McPhillips [VC++ MVP]



Sun, 27 Mar 2005 10:18:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. free halts when used malloc

2. VS-Debugger won't free the process on debug-halt

3. problems using malloc and free

4. Memory Leakage problem using malloc and free

5. memory allocation using malloc and free

6. Problem using free! - free.txt [1/1]

7. Problems freeing memory using "free"

8. memory to free or not to free, to malloc or not to malloc ?

9. malloc & free in c#

10. Override malloc,calloc,realloc and free?

11. malloc/free reference implementations

12. malloc, realloc, free questions

 

 
Powered by phpBB® Forum Software