簡體   English   中英

Valgrind報告可能的堆棧溢出 - 這是什么意思?

[英]Valgrind reporting possible stack overflow - what does it mean?

當我使用valgrind運行我的C程序文件時,我得到以下錯誤和分段錯誤。 這是什么意思?

由於一個函數的遞歸調用更深,我得到了這個錯誤

我成功地為字符指針i malloc分配了9684173個字節,並且我在一個函數的Recursivly調用中得到了分段錯誤。 所以任何解決方案?

==3100== Stack overflow in thread 1: can't grow stack to 0x7fe801ff8
==3100== 
==3100== Process terminating with default action of signal 11 (SIGSEGV)
==3100==  Access not within mapped region at address 0x7FE801FF8
==3100==    at 0x4014D8: huffman_decoding (filebits.c:471)
==3100==  If you believe this happened as a result of a stack
==3100==  overflow in your program's main thread (unlikely but
==3100==  possible), you can try to increase the size of the
==3100==  main thread stack using the --main-stacksize= flag.
==3100==  The main thread stack size used in this run was 8388608.
==3100== Stack overflow in thread 1: can't grow stack to 0x7fe801ff0
==3100== 
==3100== Process terminating with default action of signal 11 (SIGSEGV)
==3100==  Access not within mapped region at address 0x7FE801FF0
==3100==    at 0x4A2269F: _vgnU_freeres (vg_preloaded.c:58)
==3100==  If you believe this happened as a result of a stack
==3100==  overflow in your program's main thread (unlikely but
==3100==  possible), you can try to increase the size of the
==3100==  main thread stack using the --main-stacksize= flag.
==3100==  The main thread stack size used in this run was 8388608.
==3100== 
==3100== HEAP SUMMARY:
==3100==     in use at exit: 22,490,801 bytes in 179 blocks
==3100==   total heap usage: 179 allocs, 0 frees, 22,490,801 bytes allocated
==3100== 
==3100== LEAK SUMMARY:
==3100==    definitely lost: 0 bytes in 0 blocks
==3100==    indirectly lost: 0 bytes in 0 blocks
==3100==      possibly lost: 0 bytes in 0 blocks
==3100==    still reachable: 22,490,801 bytes in 179 blocks
==3100==         suppressed: 0 bytes in 0 blocks
==3100== Reachable blocks (those to which a pointer was found) are not shown.
==3100== To see them, rerun with: --leak-check=full --show-reachable=yes
==3100== 
==3100== For counts of detected and suppressed errors, rerun with: -v
==3100== Use --track-origins=yes to see where uninitialised values come from
==3100== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 4 from 4)
Segmentation fault

你要么試圖在堆棧上分配太多,要么調用遞歸函數太深。

既然你提到“我想壓縮一個大小為12 MB的大文件”,我有一種強烈的感覺,你試圖在堆棧上分配12M。

此消息意味着您正在嘗試在堆棧中分配大量數據,以解決此問題嘗試將堆棧作為possobile釋放,或者您必須使用ulimit命令增加堆棧大小

ulimit -s new_size

或者在C中使用“setrlimit”功能。

當然我不建議這樣做,如果你使用大堆棧大小,請改用malloc。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM