Motion - Memory Leaks In Motion

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 :
    • Fedora Core 3

       valgrind --tool=memcheck --leak-check=yes --trace-children=yes --leak-resolution=low
       --logfile=/tmp/motion --trace-pthread=some --show-reachable=yes ./motion

    • Debian

       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.

-- AngelCarpintero - 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

-- KennethLavrsen - 12 Aug 2005
Topic revision: r2 - 12 Aug 2005, KennethLavrsen
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.