#!/bin/ksh -p # Show all memory leaks and associated allocation stacks. me=${0##*/} if [[ $# -lt 2 || "$1" == @('-?'|'--help') ]] then output=; rc=0 [[ $# -lt 2 ]] && { output='-u2'; rc=1; } print $output "Usage: $me [-v] " print $output "-v: verbose mode, runs ::bufctl_audit on all leaks" exit $rc fi if [[ "$1" == '-v' ]] then verbose=true shift else verbose=false fi pid=$(pgrep -x $1) if [[ -z $pid ]] then print -u2 "Error: $1 not running." exit 1 fi tmpfile=$(/usr/bin/mktemp -t ${me}.XXXXXX) # Using bash here because piping commands to mdb -p in ksh doesn't work. bash -c "echo '::findleaks'|mdb -o nostop -p $pid" > $tmpfile 2>/dev/null cat $tmpfile if $verbose then # If there are leaks then process the buffers listed by findleaks if grep '^CACHE' $tmpfile > /dev/null then egrep -v '^(CACHE|---| Total| *$)' $tmpfile |\ while read j1 j2 buf rest do print "======================= ${buf}::bufctl_audit info ======================" bash -c "echo '${buf}::bufctl_audit'|mdb -o nostop -p $pid" 2>/dev/null done fi fi /usr/bin/rm $tmpfile