Valgrind like tool on Mac OS 10.7 (Lion)

2019-02-09 10:27发布

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).

2条回答
地球回转人心会变
2楼-- · 2019-02-09 11:18

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

查看更多
▲ chillily
3楼-- · 2019-02-09 11:20

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

查看更多
登录 后发表回答