C++进程内存泄露检测工具——Valgrind & GCC

1、valgrind使用

(1)    机器上要安装valgrid

修改内存大小限制,修改配置文件

coregrind/m_aspacemgr/aspacemgr-linux.c

#if  defined(VGPV_arm_linux_android)  \

       || defined(VGPV_x86_linux_android)  \

       || defined(VGPV_mips32_linux_android) \

       || defined(VGPV_arm64_linux_android)

# define  VG_N_SEGMENTS  500000

#else

# define  VG_N_SEGMENTS  3000000

#endif

 

重新编译安装

 

(2)    启动程序的命令

后台启动:

nohup valgrind  --leak-check=full  --show-reachable=yes  --trace-children=yes  --error-limit=no  --log-file=./valgrind_output.log  ./xlongsrv &

 

前台启动:

valgrind --leak-check=full  ./ xlongsrv

 

 

2、GCC内存越界检查

 

 

如gets()到buffer的内容长度超出了buffer大小,则编译、运行时都会提示。

-fstatck_protector

-fsanitize=address高版本gcc(gcc version4.8.5 20150623 (Red Hat 4.8.5-4))支持

可能需要安装libasan(sudo yum install libasan)

 

编译器所采用的以 Canaries 探测为主的堆栈保护技术,

并且以 GCC 为例展示了 SSP 的实现方式和实际效果。

最后又简单介绍了突破编译器保护的一些方法

g++ -fsanitize=address -g -o test_vsnptest_vsnp.cpp

 

3、GCC内存越界检查

使用:gcc编译选项-fstack-protector和-fstack-protector-all

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值