使用valgrind检测Android native程序的内存

下载http://valgrind.org/downloads/valgrind-3.7.0.tar.bz2,使用ndk toolchain,按照代码中的README.android编译Android版本的valgrind,push到/data分区,这里笔者push到了/data/local/valgrind/,同时把VALGRIND_LIB 环境变量设置为/data/local/valgrind/lib/valgrind

编写一个有很多内存错误的程序:


使用valgrind运行之:


得到如下结果:


这些错误可以分为如下几类:

  1. Illegal read / Illegal write errors
  2. Use of uninitialised values
  3. Use of uninitialised or unaddressable values in system calls
  4. Illegal frees
  5. When a heap block is freed with an inappropriate deallocation function
  6. Overlapping source and destination blocks
  7. Memory leak detection



你可能感兴趣的:(android)