sam_k
sam_k

Reputation: 6023

Valgrind reporting possible stack overflow - what does it mean?

When I run my C program file using valgrind, I get the following error and segmentation fault. What does it mean?

I got this error due to recursive call of one function more deep

i allocated 9684173 bytes for character pointer i malloc successfully and i got segmentation fault in Recursivly call of one funcation deeply. so any solution of this??

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

Upvotes: 0

Views: 15801

Answers (2)

A.M.M
A.M.M

Reputation: 227

This message means that you are trying to allocate a lot of data in your stack, to solve this issue try to free stack as possobile or you have to increase your stack size using ulimit commands

ulimit -s new_size

or using the function "setrlimit" in C.

Of course I don't recommend so, if you will use big stack size, use malloc instead.

Upvotes: 0

cnicutar
cnicutar

Reputation: 182609

You're either trying to allocate too much on the stack or calling a recursive function too deep.

Since you mention "i want to compress one big file which size is 12 MB" I have a strong feeling you're trying to allocate 12M on the stack.

Upvotes: 2

Related Questions