About memory leak detection.

M

mosaic

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!
 
H

Hans-Bernhard Broeker

mosaic said:
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.
 
E

Emmanuel Delahaye

In 'comp.lang.c' said:
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
 
D

Dan Pop

In said:
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
 
?

=?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=

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/)
 
K

Karthik

mosaic said:
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/manual/html_node/Allocation-Debugging.html#Allocation Debugging.

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

HTH .
 
B

Bernhard

mosaic said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top