[user1@develop tmp]$ valgrind --tool=memcheck ./a.out ==23183== Memcheck, a memory error detector ==23183== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==23183== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==23183== Command: ./a.out ==23183== ==23183== Warning: client switching stacks? SP change: 0x1fff000220 --> 0x1ff8c00218 ==23183== to suppress, use: --max-stackframe=104857608 or greater ==23183== Invalid write of size 8 ==23183== at 0x400885: main (test.cpp:5) ==23183== Address 0x1ff8c00218 is on thread 1's stack ==23183== ==23183== ==23183== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==23183== Access not within mapped region at address 0x1FF8C00218 ==23183== at 0x400885: main (test.cpp:5) ==23183== If you believe this happened as a result of a stack ==23183== overflow in your program's main thread (unlikely but ==23183== possible), you can try to increase the size of the ==23183== main thread stack using the --main-stacksize= flag. ==23183== The main thread stack size used in this run was 8388608. ==23183== Invalid write of size 8 ==23183== at 0x4A24710: _vgnU_freeres (vg_preloaded.c:59) ==23183== Address 0x1ff8c00210 is on thread 1's stack ==23183== ==23183== ==23183== Process terminating with default action of signal 11 (SIGSEGV) ==23183== Access not within mapped region at address 0x1FF8C00210 ==23183== at 0x4A24710: _vgnU_freeres (vg_preloaded.c:59) ==23183== If you believe this happened as a result of a stack ==23183== overflow in your program's main thread (unlikely but ==23183== possible), you can try to increase the size of the ==23183== main thread stack using the --main-stacksize= flag. ==23183== The main thread stack size used in this run was 8388608. ==23183== ==23183== HEAP SUMMARY: ==23183== in use at exit: 0 bytes in 0 blocks ==23183== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==23183== ==23183== All heap blocks were freed -- no leaks are possible ==23183== ==23183== For lists of detected and suppressed errors, rerun with: -s ==23183== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) Segmentation fault
[user1@develop tmp]$ valgrind --tool=memcheck ./a.out ==23334== Memcheck, a memory error detector ==23334== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==23334== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==23334== Command: ./a.out ==23334== ==23334== Warning: client switching stacks? SP change: 0x1fff000220 --> 0x1ff8c00218 ==23334== to suppress, use: --max-stackframe=104857608 or greater ==23334== Invalid write of size 8 ==23334== at 0x400885: main (test.cpp:6) ==23334== Address 0x1ff8c00218 is on thread 1's stack ==23334== ==23334== ==23334== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==23334== Access not within mapped region at address 0x1FF8C00218 ==23334== at 0x400885: main (test.cpp:6) ==23334== If you believe this happened as a result of a stack ==23334== overflow in your program's main thread (unlikely but ==23334== possible), you can try to increase the size of the ==23334== main thread stack using the --main-stacksize= flag. ==23334== The main thread stack size used in this run was 8388608. ==23334== Invalid write of size 8 ==23334== at 0x4A24710: _vgnU_freeres (vg_preloaded.c:59) ==23334== Address 0x1ff8c00210 is on thread 1's stack ==23334== ==23334== ==23334== Process terminating with default action of signal 11 (SIGSEGV) ==23334== Access not within mapped region at address 0x1FF8C00210 ==23334== at 0x4A24710: _vgnU_freeres (vg_preloaded.c:59) ==23334== If you believe this happened as a result of a stack ==23334== overflow in your program's main thread (unlikely but ==23334== possible), you can try to increase the size of the ==23334== main thread stack using the --main-stacksize= flag. ==23334== The main thread stack size used in this run was 8388608. ==23334== ==23334== HEAP SUMMARY: ==23334== in use at exit: 0 bytes in 0 blocks ==23334== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==23334== ==23334== All heap blocks were freed -- no leaks are possible ==23334== ==23334== For lists of detected and suppressed errors, rerun with: -s ==23334== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) Segmentation fault
分析
1 2
==23334== Warning: client switching stacks? SP change: 0x1fff000220 --> 0x1ff8c00218 ==23334== to suppress, use: --max-stackframe=104857608 or greater