8

I need a tool which helps me to find memory leaks in a c program in a similar way valgrind does. It should figures out when a program overwrites memory it should not (e.g. by miscalculating an array index). I learned that there is the leaks utility along with the graphical instruments app.

However I think it can just find memory allocated with new (or malloc) which was not released and is not accessible anymore. Also I learned that valgrind is supposed to work on older releases (10.5 and 10.6), but I use lion (10.7).

3
  • As written above it does not (yet) work with lion (10.7). Commented Sep 20, 2011 at 19:44
  • 1
    @Mat : Lion (10.7) is not supported yet as OP pointed out, they are working on it since june, but it doesn't seem so easy : bugs.kde.org/show_bug.cgi?id=275168 Commented Sep 20, 2011 at 19:45
  • From your link @Matthieu, it seems as though people have gotten it to work. Commented Sep 21, 2011 at 0:34

2 Answers 2

8

Valgrind 3.7.0 (released 5th November 2011) supports Lion. http://valgrind.org

Sign up to request clarification or add additional context in comments.

1 Comment

It is straight-forward to download, build and use it, too.
4

I would use the XCode developer tool MallocDebug. You should have this installed with XCode in your /Developer folder

Alternatively, you can run your application in gdb and use the native malloc logging by running

% gdb <program name>
(gdb) set env MallocStackLoggingNoCompact 1
(gdb) run

Then, you can use /usr/bin/leaks and /usr/bin/malloc_history to find obvious leaks

3 Comments

Tested it in a case where I accidentally multiplied 2 vars in an array access instead of adding them. w/o MallocStackLoggingNoCompact the bt output is useless, but after having set that it told me the exact line! Thx for the hint!
However I couldn't find MallocDebug in 10.7. Also shark is gone.. :(
Looks like MallocDebug has been replaced by the Leaks instrument in the Instruments application.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.