Diff

Differences From Artifact [ebd6df1f69]:

To Artifact [eea3ae5a09]:


     1      1   #! /bin/bash
     2      2   
            3  +LEAKCHECKFILE="$1"
     3      4   TMPFILE="${TMPDIR:-/tmp}/malloc-free-check-$$${RANDOM}${RANDOM}${RANDOM}.tmp"
            5  +export LEAKCHECKFILE TMPFILE
            6  +
            7  +if [ -z "${LEAKCHECKFILE}" ]; then
            8  +	echo "Usage: leakcheck <filename>" >&2
            9  +	echo "         filename       Name of file containing debugging output" >&2
           10  +
           11  +	exit 1
           12  +fi
     4     13   
     5         -egrep '(MALLOC|FREE|REALLOC)' "$@" | sed 's@^.*FREE(\(0x[0-9a-f]*\)).*$@free \1@;s@^.*MALLOC() = @malloc @;s@^.*REALLOC(\(0x[0-9a-f]*\)) = @realloc \1 @' > "${TMPFILE}"
           14  +egrep '(MALLOC|FREE|REALLOC)' "${LEAKCHECKFILE}" | sed 's@^.*FREE(\(0x[0-9a-f]*\)).*$@free \1@;s@^.*MALLOC() = @malloc @;s@^.*REALLOC(\(0x[0-9a-f]*\)) = @realloc \1 @' > "${TMPFILE}"
     6     15   
     7     16   cat "${TMPFILE}" | while read op addr newaddr; do
     8     17   	case "${op}" in
     9     18   		malloc)
    10     19   			if [ -z "${alloclist}" ]; then
    11     20   				alloclist="${addr}"
    12     21   			else
................................................................................
    34     43   done | tail -1 | while read leftovers; do
    35     44   	for leftover in ${leftovers}; do
    36     45   		case "${leftover}" in
    37     46   			!*)
    38     47   				leftover="$(echo "${leftover}" | cut -c 2-)"
    39     48   
    40     49   				echo "Double freed or never allocated ${leftover}:"
    41         -				grep "${leftover}" "$@" | sed 's@^@    @'
           50  +				grep "${leftover}" "${LEAKCHECKFILE}" | sed 's@^@    @'
    42     51   				echo ''
    43     52   				;;
    44     53   			*)
    45     54   				echo "Unfreed memory ${leftover}:"
    46         -				grep "${leftover}" "$@" | sed 's@^@    @'
           55  +				grep "${leftover}" "${LEAKCHECKFILE}" | sed 's@^@    @'
    47     56   				echo ''
    48     57   				;;
    49     58   		esac
    50     59   	done
    51     60   done
    52     61   
    53     62   rm -f "${TMPFILE}"