github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/scripts/goescape (about) 1 #!/usr/bin/env bash 2 3 # goescape determines the variables which are escaping to the heap for a given 4 # Go source file. Courtesy of Nathan VanBenschoten. 5 6 set -eu 7 8 if [ $# -eq 0 ] 9 then 10 echo "usage: goescape <filename>" 11 exit 1 12 fi 13 14 FILEPATH="$1" 15 DIR=$(dirname "$FILEPATH") 16 FILE=$(basename "$FILEPATH") 17 18 pushd "$DIR" > /dev/null 19 touch "$FILE" 20 21 go build -gcflags='-m' 2>&1 | \ 22 grep 'to heap' | \ 23 grep "./$FILE" 24 25 popd > /dev/null