On 9/28/12 9:54 AM, Yuxiang Cao wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: i486
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_V$
> uname output: Linux frank-laptop 2.6.32-42-generic #96-Ubuntu SMP Wed Aug 15 
> 18:57:09 UTC 2012 i686 GNU/Linux
> Machine Type: i486-pc-linux-gnu
> 
> Bash Version: 4.1
> Patch Level: 5
> Release Status: release
> 
> Description:
>         segmentation fault occur when I use deep recursive function.
> 
> Repeat-By:
> the following content is my code
>        recursion()
> {
>     if [ $1 -ne 15000 ] ;then
>         echo $1
>         let i=$1+1
>         recursion $i
>     fi
>     exit
> }
> recursion 1
> 
> 
> Fix:
>         I use ulimit -s to find stack size, which is 8192kbytes. Then I use 
> valgrind to record the stack size which give me this information.
> test.sh: xmalloc: ../bash/unwind_prot.c:308: cannot allocate 172 bytes 
> (8359936 bytes allocated)
> So from the above information I think this is not a stack overflow, and that 
> is a real fault in this program.

It's not; deep-enough recursion will eventually exhaust available
resources, no matter their limits, and cause the process to crash.  If
the kernel decides that you can't have any more heap space when malloc
requests it, then that's that.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to