读取已释放区域 2 test4.c (-/calg/memchk)-gedit 一口× 文件(F)编辑(E)查看(M搜索(S)工具(D文档(D)帮助H) 产口打开、也保存合◆撤消形晶鹤 ☐test4.c× 1 #include <stdlib.h> 2 3 int main(void) 4 { 5 char *x malloc(sizeof(int)); 6 free(x); 7 int a *x +1; 8 return a; 9 [wgsheng@calg memchk]$gcc test4.c -o test4 -g [wgsheng@calg memchk]$valgrind ./test4 ==3193==Memcheck,a memory error detector ==3193==Copyright (C)2002-2012,and GNU GPL'd,by Julian Seward et al. ==3193== Using Valgrind-3.8.1 and LibVEX;rerun with -h for copyright info ==3193==Command:./test4 ==3193=三 ==3193==Invalid read of size 1 -3193== at 0x804841D:main (test4.c:7) ==3193==Address 0x4027028 is 0 bytes inside a block of size 4 free'd ==3193== at 0x4006CAF:free (vg_replace_malloc.c:446) ==3193== by 0x8048418:main (test4.c:6) ==3193== ==3193== ==3193==HEAP SUMMARY: ==3193== in use at exit:0 bytes in 0 blocks ==3193== total heap usage:1 allocs,1 frees,4 bytes allocated =3193= 国终端8Shel‖输出 C~跳格宽度:4~行6,列13 插入 11
读取已释放区域 11
内存双重释放 2 test5.c (-/calg/memchk)-gedit 一口× 文件()编辑(E)查看M搜索(S)工具(円文档(D)帮助(H) 口打开也保存台◆撤消 test5.c× 1 #include <stdlib.h> 2 3 int main(void) 4 { 5 char *x malloc(sizeof(int)) 6 free(x); 7 free(x); 8 return EXIT_SUCCESS; 9 [wgsheng@calg memchk]$gcc test5.c -o test5 -g [wgsheng@calg memchk]$valgrind ./test5 ==3209==Memcheck,a memory error detector ==3209==Copyright (C)2002-2012,and GNU GPL'd,by Julian Seward et al. ==3209==Using Valgrind-3.8.1 and LibVEX;rerun with -h for copyright info ==3209==Command:./test5 ==3209== ==3209--Invalld free()/delete delete[]7 realloc() =3209== at 0x4006CAF:free (vg_replace_malloc.c:446) ==3209 by 0x8048424:main (test5.c:7) ==3209== Address 0x4027028 is 0 bytes inside a block of size 4 free'd ==3209== at 0x4006CAF:free (vg_replace_malloc.c:446) ==3209== by 0x8048418:main (test5.c:6) ==3209== ==3209== ==3209==HEAP SUMMARY: ==3209== in use at exit:0 bytes in 0 blocks =3209= total heap usage:1 allocs,2 frees,4 bytes allocated 国终端始Shell输出 C~跳格宽度:4~行8,列24 插入 12
内存双重释放 12