proc ckalloc {addr size file line} { variable store variable i if {[llength [array names store *,$addr,*]]} { puts stderr "Double alloc at $addr: $size $file $line" } set store([incr i],$addr,$size) "$file $line" } proc ckfree {addr size file line} { variable store array unset store *,$addr,$size } set i 0 source [lindex $argv 0] foreach name [array names store] { foreach {i addr size} [split $name ,] {break} lappend out [list $i "LEAK: $addr $size $store($name)"] } puts [join [lsort -index 0 -integer $out] \n]
AK notes:
- How can a double allocation for the same address happen ?
- Also, if it can happen, is the size of the struct not irrelevant for the collision ? Right now the script will not detect a collision on the same address with different sizes.
- ckfree should be extended to check if there is data for the adress available. Because if not then we have found a double-free.