Re: How to find memory leaks from an running application

Philippe Waroquiers <[email protected]>
Newsgroups gmane.comp.debugging.valgrind
Message-ID <[email protected]>
On Thu, 2019-06-20 at 11:04 +0530, subhasish Karmakar wrote:
> Hi,
> 
> I have an application running on embedded linux.
> After running for hours my application causes out of memory issue.
> How can I get memory leak report periodically when the application is running?
> It's a process with "while(1)" loop.

You can search leaks with valgrind while your program is running.

Different techniques can be used for that:
  * Inside your code, you add calls to client requests
    such as VALGRIND_DO_LEAK_CHECK
  * From the shell, you can use 'vgdb' to launch
    a leak search using the monitor request 'leak check'
  * Using gdb+vgdb, you can also launch such a leak check.
    Compared to the previous techniques, the advantage is
    that you can just put breakpoints where you want, and
    launch leak searches when a breakpoints is reached.
    You can also explore the 'logical leaks' (increase of
    memory due to still reachable memory) using the monitor
    request 'who_points_at'.

Note that these leak searches can show a 'delta leak' report,
i.e. pinpoint at the new allocations since the previous leak
search.

See user manual for more details, e.g.
http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.monitor-commands
and 
http://www.valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver

Philippe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.