Find Memory Leaks in Motion
Why that is important ?
Any program that use dynamic allocation of memory ( malloc , calloc , etc ... ) , should free it when that memory won't be used and release this memory to system. There're some conditions where don't free an allocated chunk of memory could be dangerous ,i.ex allocate a chunk of memory that hasn't been freed before , that is called LEAK . When a LEAK happen this chunk of memory is LOST ( we cannot freed from inside the application ) so if we have a LEAK inside a loop the application is wasting chunks of memory that can't be used until the application end.
How to find memory LEAKS ?
First we need to use any memory checker that will allow us to find memory leaks , there's an excellent tool called Valgrind
, you can get it from most of distros ( yum install valgrind , apt-get install valgrind , etc ... ).
How to use Valgrind ?
A simple example to use valgring to find memory leaks in motion :
- First launch valgrind with its options :
valgrind --tool=memcheck --leak-check=yes --trace-children=yes --leak-resolution=low
--logfile=/tmp/motion --trace-pthread=some --show-reachable=yes ./motion
valgrind --leak-check=yes --trace-children=yes --leak-resolution=low --logfile=/tmp/motion
--trace-pthread=some --show-reachable=yes ./motion
- Kill the program with kill -15 pid , otherwise valgrind won't report anything.
- Take a look to file specified with --logfile= option , it will be /tmp/motion.pid , where pid is the pid that had motion.
- 20 Apr 2005
Looking for leaks in 3.2.2
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./motion -c /usr/local/etc/motion.conf
and to finish properly
kill -15 valgrind_pid
- 12 Aug 2005