Advertisement
Advertisement


How do I use valgrind to find memory leaks?


Question

How do I use valgrind to find the memory leaks in a program?

Please someone help me and describe the steps to carryout the procedure?

I am using Ubuntu 10.04 and I have a program a.c, please help me out.

2011/03/15
1
189
3/15/2011 12:53:17 PM


Try this:

valgrind --leak-check=full -v ./your_program

As long as valgrind is installed it will go through your program and tell you what's wrong. It can give you pointers and approximate places where your leaks may be found. If you're segfault'ing, try running it through gdb.

2016/12/16

You can run:

valgrind --leak-check=full --log-file="logfile.out" -v [your_program(and its arguments)]
2014/10/06

You can create an alias in .bashrc file as follows

alias vg='valgrind --leak-check=full -v --track-origins=yes --log-file=vg_logfile.out'

So whenever you want to check memory leaks, just do simply

vg ./<name of your executable> <command line parameters to your executable>

This will generate a Valgrind log file in the current directory.

2020/05/21

Source: https://stackoverflow.com/questions/5134891
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]