内存检测方法
内存检测工具根据平台arch32\nt\gcc-arm-linux-gnueabi已经交叉编译可直接安装使用
安装
- valgrind-3.23.0.tar.gz 拷贝到/mnt
2.执行命令解压
tar xvf valgrind-3.23.0.tar.gz
3.执行命令 整个包添加执行权限
chmod +x /mnt/valgrind-3.23.0/ -R
使用
1.执行命令添加临时环境变量
export VALGRIND_LIB=/mnt/valgrind-3.23.0/libexec/valgrind 或者/mnt/valgrind-3.23.0/valgrind.sh
2.执行命令排查问题
/mnt/valgrind-3.23.0/bin/valgrind --error-limit=no --leak-check=full --log-file=leak.log --tool=memcheck ./iec61850
注意:若异常报ld-linux-armhf.so.3请替换平台板子库ld-2.21.so,从相应交叉编译器里取
strings /lib/libstdc++.so.6 |grep GLIBCXX
valgrind(memcheck)包含7类错误
1,illegal read/illegal write errors
提示信息:[invalid read of size 4]
2,use of uninitialised values
提示信息:[Conditional jump or move depends on uninitialised value]
3,use of uninitialised or unaddressable values in system calls
提示信息:[syscall param write(buf) points to uninitilaised bytes]
4,illegal frees
提示信息:[invalid free()]
5,when a heap block is freed with an inappropriate deallocation function
提示信息:[Mismatched free()/delete/delete[]]
6,overlapping source and destination blocks
提示信息:[source and destination overlap in memcpy(,)]
7,memory leak detection
1),still reachable
内存指针还在还有机会使用或释放,指针指向的动态内存还没有被释放就退出了
2),definitely lost
确定的内存泄露,已经不能访问这块内存
3),indirectly lost
指向该内存的指针都位于内存泄露处
4),possibly lost
可能的内存泄露,仍然存在某个指针能够快速访问某块内存,但该指针指向的已经不是内存首位置
Invalid write of size 1 : 堆内存越界访问
Source and destination overlap in memcpy : 内存重叠
Invalid free() / delete / delete[] : 重复释放
Use of uninitialised value of size 4 : 非法指针
HEAP SUMMARY:堆内存使用摘要
LEAK SUMMARY : 泄露摘要
ERROR SUMMARY: 错误总数
LEAK SUMMARY:内存泄漏总结(分类)
definitely lost: 4 bytes in 1 blocks:绝对丢失,这种情况应该由程序员来解决,下面几种情况,可以当作参考
indirectly lost: 0 bytes in 0 blocks:间接丢失
possibly lost: 0 bytes in 0 blocks:可能丢失
still reachable: 0 bytes in 0 blocks:仍然可以访问
suppressed: 0 bytes in 0 blocks:抑制错误中的丢失
valgrind介绍、安装与使用: [https://blog.youkuaiyun.com/mijichui2153/article/details/85240349)
链接: [https://blog.youkuaiyun.com/aqieye/article/details/134836159)
链接: [https://blog.youkuaiyun.com/tanxuan231/article/details/128386790)