Hi,

I've just to report a memory leak caused by a shell function which
uses an echo as last line in the shell function.

-----------------------------------------------------------------------
#!/usr/bin/ksh

PATH=/bin:/usr/bin:/usr/sbin:/sbin

# Description:  Get the interval to sample information
# Output:       interval seconds
getSampleInterval()
{
    # Example for this arithmetic, suppose the next time is 45 second
    # If current second is in [35, 40], such as 38, 
    #   the interval should be 10 - 38 % 10 + 5 = 7
    # If current second is in [41, 45], such as 42,
    #   the interval should be 10 - 42 % 10 - 5 = 3
    # If the current second is 45, the interval should be 10 - 45 % 10 - 5 = 0

    typeset -ilu _currSec=$(date +%S)
    typeset -ilu _interval

    ((_interval=10-(_currSec%10)))

    if ((_interval >= 5))
    then 
        ((_interval=_interval-5))
    else
        ((_interval=_interval+5))
    fi

    echo $_interval    
}

typeset -ilu times=0
typeset -ilu interval

while [ 1 -eq 1 ]
do
    # First, get the interval to check
    interval=$(getSampleInterval)
    sleep $interval

    ((times++))

    state=$(egrep '^VmData|^VmRSS|^VmSize' </proc/$$/status)
    [ "$state" != "$oldstate" ] && echo $state
    oldstate="$state"
done
-----------------------------------------------------------------------

here the shell function getSampleInterval cause the mem leak,
using a simply return/exit value does not show this behaviour.


       Werner

-- 
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to