By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,689 Members | 1,731 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,689 IT Pros & Developers. It's quick & easy.

About memory leak detection.

P: n/a
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!
Nov 14 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
mosaic <mo****@hotmail.com> 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 (br*****@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Nov 14 '05 #2

P: n/a
In 'comp.lang.c', mosaic <mo****@hotmail.com> 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/
Nov 14 '05 #3

P: n/a
In <cd**********@mail.cn99.com> mosaic <mo****@hotmail.com> 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: Da*****@ifh.de
Nov 14 '05 #4

P: n/a
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/)
Nov 14 '05 #5

P: n/a
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.
Nov 14 '05 #6

P: n/a
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.
Nov 14 '05 #7

P: n/a
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
Nov 14 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.