c - Valgrind 报告可能的堆栈溢出 - 这是什么意思?

标签 c memory out-of-memory bit

当我使用 valgrind 运行 C 程序文件时,出现以下错误和段错误。这是什么意思?

由于递归调用更深层的一个函数,我收到此错误

我为字符指针分配了 9684173 字节 我 malloc 成功,但我在一个函数的递归调用中遇到了段错误。那么有什么解决方案吗??

==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。

关于c - Valgrind 报告可能的堆栈溢出 - 这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7950769/

相关文章:

c - 在 ‘%xmm1’ 中修复未知的寄存器名称 ‘asm’ ?

c - uint8_t 数组 - 内存中的数据

C++ - 获取特定内存地址的值

memory - 硬盘直接内存访问的目的是什么?

javascript - 使用 PhoneGap 处理 iOS 内存警告

c# - 如何在 C# 中处理大文件?

c - 在 C 中执行 pragma pack(1) 的缺点是什么?

c - 多个无关进程同步UART

android - 使用 PNG 图像的 SplashScreen 导致 Android.Views.InflateException,然后是 OutOfMemory

c# - HttpClient.getAsync() 内存不足异常