造成内存泄漏的原因有几个,具体的原因分析可以自行百度,这里主要分析malloc和free不匹配造成的。 这里用Valgrind这个工具来排查。 主要是讲一下载海思平台上安装这个工具。
我首先按照网上的方法来安装出现以下问题,如果你们也出现 这个问题,可以试一下我的方法
valgrind-m_debuglog.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
Makefile:2818: recipe for target 'valgrind' failed
make[3]: *** [valgrind] Error 1
make[3]: Leaving directory '/var/valgrind-3.15.0/coregrind'
Makefile:1915: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/var/valgrind-3.15.0/coregrind'
Makefile:842: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/var/valgrind-3.15.0'
Makefile:711: recipe for target 'all' failed
make: *** [all] Error 2
工具大家可以自行百度下载,之后我找到自己的压缩包再上传吧!下面是安装步骤
1、把压缩包拷贝到Ubuntu上解压
2、解压之后进入解压的目录,在正式安装之前需要先安装automake。如果Ubuntu可以上网可以直接apt-get install automake来安装,否则就只能下载压缩包解压来解决。
3、进入解压目录之后有一个config文件,在linux下安装过软件都知道这个是安装配置文件, 这里要用在arm平台,所以需要做一下修改。vi config 把armv7*)修改成armv7*|arm)。这个可以直接搜索。进入vi之后先不要插入,输入/armv7,回车就可以。
4、配置环境变量
export CC=arm-hisiv500-linux-gcc
export AR=arm-hisiv500-linux-ar
export LD=arm-hisiv500-linux-ld
5、./configure --host=arm-hisiv500-linux --prefix=/nfs/valgrind/ --enable-only32bit
最后的--enable-only32bit是你平台是32位还是64位,看自己的情况
6、make;make install
7、安装之后在coregrind目录里有一个valgrind程序,拷贝到单板上就可以使用
至于使用的话,我们公司的工程太乱了,没办法用这个工具来排查, 所以我就没有使用,具体的使用方法可以参考其他人的博客