valgrind (在linux平台,使用 valgrind 检测可执行文件的内存泄漏)

valgrind

valgrind (在linux平台,使用 valgrind 检测可执行文件的内存泄漏)

安装valgrind

[root@lwh Game]# yum install valgrind

[root@lwh Game]# valgrind --version
valgrind-3.15.0

使用valgrind

# 显示所有的内存泄漏
[root@lwh Game]# valgrind --leak-check=full ./execute 

# 显示所有的内存泄漏,更加详细的内存调用过程(相对于上一条,本条返回的信息量有点大)
[root@lwh Game]# valgrind --leak-check=full --show-leak-kinds=all ./execute 
# 1、启动可执行程序
[root@lwh Game]# valgrind --leak-check=full ./execute 
==13510== Memcheck, a memory error detector
==13510== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13510== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==13510== Command: ./execute
==13510== 

# 2、执行execute

# 3、Ctrl + c 停止程序之后,显示如下
==13510== Process terminating with default action of signal 2 (SIGINT)
==13510==    at 0x6015E43: __epoll_wait_nocancel (in /usr/lib64/libc-2.17.so)
==13510==    by 0x505EE8A: ZinxKernel::Run() (in /usr/lib/libzinx.so)
==13510==    by 0x505F387: ZinxKernel::Zinx_Run() (in /usr/lib/libzinx.so)
==13510==    by 0x408D6A: main (main.cpp:29)
==13510== 
==13510== HEAP SUMMARY:
==13510==     in use at exit: 39,517 bytes in 557 blocks
==13510==   total heap usage: 6,227 allocs, 5,670 frees, 294,572 bytes allocated
==13510== 
==13510== LEAK SUMMARY:
==13510==    definitely lost: 0 bytes in 0 blocks # 绝对是内存泄漏的字节数(此处时0块0字节)
==13510==    indirectly lost: 0 bytes in 0 blocks # 间接的内存泄漏
==13510==      possibly lost: 0 bytes in 0 blocks # 可能的内存泄漏
==13510==    still reachable: 39,517 bytes in 557 blocks # 仍然可访问的...
==13510==                       of which reachable via heuristic:
==13510==                         stdstring          : 8,201 bytes in 202 blocks
==13510==         suppressed: 0 bytes in 0 blocks
==13510== Reachable blocks (those to which a pointer was found) are not shown.
==13510== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==13510== 
==13510== For lists of detected and suppressed errors, rerun with: -s
==13510== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

[root@lwh Game]# 

猜你喜欢

转载自blog.csdn.net/liangwenhao1108/article/details/108619426