Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > About memory leak detection.

Reply
Thread Tools

About memory leak detection.

 
 
mosaic
Guest
Posts: n/a
 
      07-15-2004
Hi, all
I really interested in how to check the memory leak of a program.
Your smart guys, do you have excellent ideas that could share with me?
Thank you.

The following is my idea:

In C programming language, there's a "malloc", there must a "free",
my solution of the detection of leak is, find the corresponding "free"
of "malloc". This the first condition.

Another one is much more difficult, the lost of a pointer. I think,
once a pointer is defined, it should be registered. Any operations on
pointer, like assigned or "free", all the operation must be recorded!
So, we can find the lost of pointer and return to programmers.

This is code-based detection.

Application-based detection needs asm knowledge, I will try it then.

Need your comments and advice. Thank you!
 
Reply With Quote
 
 
 
 
Hans-Bernhard Broeker
Guest
Posts: n/a
 
      07-15-2004
mosaic <(E-Mail Removed)> wrote:

> In C programming language, there's a "malloc", there must a "free",
> my solution of the detection of leak is, find the corresponding "free"
> of "malloc". This the first condition.


This is also impossible to do outside the running program. No other
instance can possibly determine with any reliability which individual
malloc()ed block a given call of free() will actually act upon.

--
Hans-Bernhard Broeker ((E-Mail Removed)-aachen.de)
Even if all the snow were burnt, ashes would remain.
 
Reply With Quote
 
 
 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      07-15-2004
In 'comp.lang.c', mosaic <(E-Mail Removed)> wrote:

> Hi, all
> I really interested in how to check the memory leak of a program.
> Your smart guys, do you have excellent ideas that could share with me?
> Thank you.
>
> The following is my idea:
>
> In C programming language, there's a "malloc", there must a "free",


Real-life is not that simple. It may have calloc(), and more tricky(),
realloc() !

> my solution of the detection of leak is, find the corresponding "free"
> of "malloc". This the first condition.
>
> Another one is much more difficult, the lost of a pointer. I think,
> once a pointer is defined, it should be registered. Any operations on
> pointer, like assigned or "free", all the operation must be recorded!
> So, we can find the lost of pointer and return to programmers.
>
> This is code-based detection.
>
> Application-based detection needs asm knowledge, I will try it then.


FYI (drop me an email if you are stuck):

http://mapage.noos.fr/emdel/sysalloc_um.htm
http://mapage.noos.fr/emdel/clib/ed/inc/SYSALLOC.H
http://mapage.noos.fr/emdel/clib/ed/src/SYSALLOC.C

Missing stuffs at:
http://mapage.noos.fr/emdel/clib.htm

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      07-15-2004
In <cd5tsp$uql$(E-Mail Removed)99.com> mosaic <(E-Mail Removed)> writes:

> I really interested in how to check the memory leak of a program.


For starters, use one of the many debugging malloc implementations
available that also includes memory leak detection. Choose one coming
with source code, so that you can see how it is done. See the FAQ or
google yourself.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
=?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=
Guest
Posts: n/a
 
      07-15-2004
On Thu, 15 Jul 2004 20:37:26 +0800, mosaic wrote:

> Hi, all
> I really interested in how to check the memory leak of a program.
> Your smart guys, do you have excellent ideas that could share with me?
> Thank you.
>
> The following is my idea:
>
> In C programming language, there's a "malloc", there must a "free",
> my solution of the detection of leak is, find the corresponding "free"
> of "malloc". This the first condition.
>
> Another one is much more difficult, the lost of a pointer. I think,
> once a pointer is defined, it should be registered. Any operations on
> pointer, like assigned or "free", all the operation must be recorded!
> So, we can find the lost of pointer and return to programmers.
>
> This is code-based detection.
>
> Application-based detection needs asm knowledge, I will try it then.
>
> Need your comments and advice. Thank you!

The "Standford Checker" already has a lot going when it comes to C source
code analyzis, there are probably some interresting papers.
http://metacomp.stanford.edu/

(or for something similar; http://smatch.sourceforge.net/)
 
Reply With Quote
 
Karthik
Guest
Posts: n/a
 
      07-15-2004
mosaic wrote:
> Hi, all
> I really interested in how to check the memory leak of a program.
> Your smart guys, do you have excellent ideas that could share with me?
> Thank you.
>
> The following is my idea:
>
> In C programming language, there's a "malloc", there must a "free",
> my solution of the detection of leak is, find the corresponding "free"
> of "malloc". This the first condition.
>
> Another one is much more difficult, the lost of a pointer. I think,
> once a pointer is defined, it should be registered. Any operations on
> pointer, like assigned or "free", all the operation must be recorded!
> So, we can find the lost of pointer and return to programmers.
>
> This is code-based detection.
>
> Application-based detection needs asm knowledge, I will try it then.


Well - the whole idea of memory detection is tied closely to the
implementation. For eg, one memory leak detector that i could think is
the mtrace utility .


http://www.gnu.org/software/libc/man...on%20Debugging.

This one is really good, but as i said before, works only where you
have glibc implementation .

HTH .

--
Karthik.
 
Reply With Quote
 
mosaic
Guest
Posts: n/a
 
      07-16-2004
Nils O. Selåsdal 写道:
> On Thu, 15 Jul 2004 20:37:26 +0800, mosaic wrote:
>
>
>>Hi, all
>> I really interested in how to check the memory leak of a program.
>>Your smart guys, do you have excellent ideas that could share with me?
>> Thank you.
>>
>>The following is my idea:
>>
>> In C programming language, there's a "malloc", there must a "free",
>>my solution of the detection of leak is, find the corresponding "free"
>>of "malloc". This the first condition.
>>
>> Another one is much more difficult, the lost of a pointer. I think,
>>once a pointer is defined, it should be registered. Any operations on
>>pointer, like assigned or "free", all the operation must be recorded!
>>So, we can find the lost of pointer and return to programmers.
>>
>> This is code-based detection.
>>
>>Application-based detection needs asm knowledge, I will try it then.
>>
>> Need your comments and advice. Thank you!

>
> The "Standford Checker" already has a lot going when it comes to C source
> code analyzis, there are probably some interresting papers.
> http://metacomp.stanford.edu/
>
> (or for something similar; http://smatch.sourceforge.net/)


Thank you very much for your kind suggestiones. I will try to hack the
papers and work on my own code.
And, thank you all.
 
Reply With Quote
 
Bernhard
Guest
Posts: n/a
 
      07-16-2004
mosaic wrote:

> Hi, all
> I really interested in how to check the memory leak of a program.
> Your smart guys, do you have excellent ideas that could share with me?
> Thank you.
>
> The following is my idea:
>
> In C programming language, there's a "malloc", there must a "free",
> my solution of the detection of leak is, find the corresponding "free"
> of "malloc". This the first condition.
>
> Another one is much more difficult, the lost of a pointer. I think,
> once a pointer is defined, it should be registered. Any operations on
> pointer, like assigned or "free", all the operation must be recorded!
> So, we can find the lost of pointer and return to programmers.
>
> This is code-based detection.
>
> Application-based detection needs asm knowledge, I will try it then.
>
> Need your comments and advice. Thank you!


There exist a lot of Tools doing the job for you, but unfortunatly they
are not for free (BoundsChecker is a very good one, I work with, but it
is expensive ~1000 ?).

If you work with Dev C++ from MS they have a lot of Debugging-Macros,
which are very usefull. Search for 'memory leaks' and you will get a lot
of useful hints.

best regards
Bernhard
 
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
Memory leak even after deleting memory pointers from vector cham C++ 5 09-25-2008 10:30 AM
Leak or no leak ?? Richard Heathfield C Programming 4 07-10-2006 11:37 AM
Dynamic memory allocation and memory leak... s.subbarayan C Programming 10 03-22-2005 02:48 PM
Memory leak??? (top reporting high memory usage under Solaris) Mark Probert Ruby 4 02-09-2005 06:13 PM
Wireless Zero Configuration Memory Leak?? =?Utf-8?B?Umlja3NjaHVsdHox?= Wireless Networking 3 01-19-2005 11:26 PM



Advertisments