1#
2# This script looks for memory leaks by analyzing the output of "sqlite"
3# when compiled with the MEMORY_DEBUG=2 option.
4#
5/[0-9]+ malloc / {
6  mem[$6] = $0
7}
8/[0-9]+ realloc / {
9  mem[$8] = "";
10  mem[$10] = $0
11}
12/[0-9]+ free / {
13  if (mem[$6]=="") {
14    print "*** free without a malloc at",$6
15  }
16  mem[$6] = "";
17  str[$6] = ""
18}
19/^string at / {
20  addr = $4
21  sub("string at " addr " is ","")
22  str[addr] = $0
23}
24END {
25  for(addr in mem){
26    if( mem[addr]=="" ) continue
27    print mem[addr], str[addr]
28  }
29}
30