About memory leak detection.

Discussion in 'C Programming' started by mosaic, Jul 15, 2004.

  1. mosaic

    mosaic Guest

    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!
     
    mosaic, Jul 15, 2004
    #1
    1. Advertising

  2. mosaic <> 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 (-aachen.de)
    Even if all the snow were burnt, ashes would remain.
     
    Hans-Bernhard Broeker, Jul 15, 2004
    #2
    1. Advertising

  3. In 'comp.lang.c', 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",


    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/
     
    Emmanuel Delahaye, Jul 15, 2004
    #3
  4. mosaic

    Dan Pop Guest

    In <cd5tsp$uql$99.com> mosaic <> 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:
     
    Dan Pop, Jul 15, 2004
    #4
  5. 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/)
     
    =?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=, Jul 15, 2004
    #5
  6. mosaic

    Karthik Guest

    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/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 .

    --
    Karthik.
     
    Karthik, Jul 15, 2004
    #6
  7. mosaic

    mosaic Guest

    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.
     
    mosaic, Jul 16, 2004
    #7
  8. mosaic

    Bernhard Guest

    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
     
    Bernhard, Jul 16, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. __jakal__

    c++ memory leak detection

    __jakal__, Apr 28, 2004, in forum: C++
    Replies:
    9
    Views:
    5,074
    StarDrago
    May 24, 2012
  2. Spur
    Replies:
    1
    Views:
    402
    Howard Hinnant
    May 9, 2004
  3. Winbatch

    Memory Leak Detection

    Winbatch, Feb 23, 2005, in forum: C++
    Replies:
    11
    Views:
    8,291
    NitinTheEmbeddedFreak
    Apr 15, 2009
  4. Replies:
    8
    Views:
    993
    Ian Collins
    Nov 3, 2006
  5. Archana

    Memory Leak detection

    Archana, Feb 4, 2008, in forum: C++
    Replies:
    1
    Views:
    338
    Ian Collins
    Feb 4, 2008
Loading...

Share This Page