Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/tests/leaks.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2012 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
builtin vmstate 2>/dev/null || exit 0
21
22
function err_exit
23
{
24
print -u2 -n "\t"
25
print -u2 -r ${Command}[$1]: "${@:2}"
26
let Errors+=1
27
}
28
alias err_exit='err_exit $LINENO'
29
30
Command=${0##*/}
31
integer Errors=0
32
33
# test for variable reset leak #
34
35
function test_reset
36
{
37
integer i n=$1
38
39
for ((i = 0; i < n; i++))
40
do u=$i
41
done
42
}
43
44
n=1000
45
46
# one round to get to steady state -- sensitive to -x
47
48
test_reset $n
49
a=0$(vmstate --format='+%(size)u')
50
b=0$(vmstate --format='+%(size)u')
51
52
test_reset $n
53
a=0$(vmstate --format='+%(size)u')
54
test_reset $n
55
b=0$(vmstate --format='+%(size)u')
56
57
if (( b > a ))
58
then err_exit "variable value reset memory leak -- $((b-a)) bytes after $n iterations"
59
fi
60
61
# buffer boundary tests
62
63
for exp in 65535 65536
64
do got=$($SHELL -c 'x=$(printf "%.*c" '$exp' x); print ${#x}' 2>&1)
65
[[ $got == $exp ]] || err_exit "large command substitution failed -- expected $exp, got $got"
66
done
67
68
data="(v=;sid=;di=;hi=;ti='1328244300';lv='o';id='172.3.161.178';var=(k='conn_num._total';u=;fr=;l='Number of Connections';n='22';t='number';))"
69
read -C stat <<< "$data"
70
a=0$(vmstate --format='+%(size)u')
71
for ((i=0; i < 500; i++))
72
do print -r -- "$data"
73
done | while read -u$n -C stat
74
do :
75
done {n}<&0-
76
b=0$(vmstate --format='+%(size)u')
77
(( b > a )) && err_exit 'memory leak with read -C when deleting compound variable'
78
79
read -C stat <<< "$data"
80
a=0$(vmstate --format='+%(size)u')
81
for ((i=0; i < 500; i++))
82
do read -C stat <<< "$data"
83
done
84
b=0$(vmstate --format='+%(size)u')
85
(( b > a )) && err_exit 'memory leak with read -C when using <<<'
86
87
exit $((Errors<125?Errors:125))
88
89