Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Double free and memory leak

Reply
Thread Tools

Double free and memory leak

 
 
Harish
Guest
Posts: n/a
 
      04-01-2005
Hi,

I am newbie to this field, So can anyone clear my doubt. I have an
application that leaks memory recursively, but I don't find any cause
for that. I have checked for allocation and deallocation of every
piece of memory. All I can find is a double free on a buffer, which is
in an infinite loop.
Can a Double free bug cause memory leaks? My thinking is based on the
implementation of malloc/free, this causes memory corruption and in a
rare case the freed buffer may be reallocated in such a way that the
second free causes only a part of the buffer to be freed, or making it
impossible to free some other buffer. Does anyone agree with me?

Thanks in advance,
regards,
harish
 
Reply With Quote
 
 
 
 
Mike Jolley
Guest
Posts: n/a
 
      04-01-2005
"Harish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Can a Double free bug cause memory leaks? My thinking is based on the
> implementation of malloc/free, this causes memory corruption and in a
> rare case the freed buffer may be reallocated in such a way that the
> second free causes only a part of the buffer to be freed, or making it
> impossible to free some other buffer. Does anyone agree with me?


In my experience, freeing a pointer that's already been freed causes
heap corruption. This could result in any or all of the symptoms
you mentioned. Even if it's possible for an implementation to detect
a double-delete, maybe the second delete happens long after the
first, i.e. if another thread interrupted my thread in betwen.


 
Reply With Quote
 
 
 
 
David White
Guest
Posts: n/a
 
      04-01-2005
"Harish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I am newbie to this field, So can anyone clear my doubt. I have an
> application that leaks memory recursively, but I don't find any cause
> for that. I have checked for allocation and deallocation of every
> piece of memory. All I can find is a double free on a buffer, which is
> in an infinite loop.
> Can a Double free bug cause memory leaks?


Anything can happen.

> My thinking is based on the
> implementation of malloc/free, this causes memory corruption and in a
> rare case the freed buffer may be reallocated in such a way that the
> second free causes only a part of the buffer to be freed, or making it
> impossible to free some other buffer. Does anyone agree with me?


Unless nothing has happened in the meantime and the allocator detects that
the block is already free or harmlessly marks an already-free block free
again, it will most likely be completely screwed up and you couldn't predict
the effect.

DW


 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      04-01-2005
Mike Jolley wrote:
> "Harish" <(E-Mail Removed)> wrote in message
>
>> Can a Double free bug cause memory leaks? My thinking is based on
>> the implementation of malloc/free, this causes memory corruption
>> and in a rare case the freed buffer may be reallocated in such a
>> way that the second free causes only a part of the buffer to be
>> freed, or making it impossible to free some other buffer. Does
>> anyone agree with me?

>
> In my experience, freeing a pointer that's already been freed
> causes heap corruption. This could result in any or all of the
> symptoms you mentioned. Even if it's possible for an
> implementation to detect a double-delete, maybe the second
> delete happens long after the first, i.e. if another thread
> interrupted my thread in betwen.


Any use of a pointer that has been freed leads to undefined
behaviour. The safe course is usually to set it to NULL
immediately after freeing. Of course, this doesn't handle copies
that may be lying around.

F'ups set to c.l.c. This is a C question, not C++, and virtually
nothing should be cross-posted between the groups.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Leak or no leak ?? Richard Heathfield C Programming 4 07-10-2006 11:37 AM
Double free and memory leak Harish C++ 3 04-01-2005 06:27 AM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM



Advertisments