/ Hex Artifact Content
Login

Artifact b744b6109566206c746d826f6ecdba34662216bc:


0000: 23 0a 23 20 54 68 69 73 20 73 63 72 69 70 74 20  #.# This script 
0010: 6c 6f 6f 6b 73 20 66 6f 72 20 6d 65 6d 6f 72 79  looks for memory
0020: 20 6c 65 61 6b 73 20 62 79 20 61 6e 61 6c 79 7a   leaks by analyz
0030: 69 6e 67 20 74 68 65 20 6f 75 74 70 75 74 20 6f  ing the output o
0040: 66 20 22 73 71 6c 69 74 65 22 20 0a 23 20 77 68  f "sqlite" .# wh
0050: 65 6e 20 63 6f 6d 70 69 6c 65 64 20 77 69 74 68  en compiled with
0060: 20 74 68 65 20 4d 45 4d 4f 52 59 5f 44 45 42 55   the MEMORY_DEBU
0070: 47 3d 32 20 6f 70 74 69 6f 6e 2e 0a 23 0a 2f 5b  G=2 option..#./[
0080: 30 2d 39 5d 2b 20 6d 61 6c 6c 6f 63 20 2f 20 7b  0-9]+ malloc / {
0090: 0a 20 20 6d 65 6d 5b 24 36 5d 20 3d 20 24 30 0a  .  mem[$6] = $0.
00a0: 7d 0a 2f 5b 30 2d 39 5d 2b 20 72 65 61 6c 6c 6f  }./[0-9]+ reallo
00b0: 63 20 2f 20 7b 0a 20 20 6d 65 6d 5b 24 38 5d 20  c / {.  mem[$8] 
00c0: 3d 20 22 22 3b 0a 20 20 6d 65 6d 5b 24 31 30 5d  = "";.  mem[$10]
00d0: 20 3d 20 24 30 0a 7d 0a 2f 5b 30 2d 39 5d 2b 20   = $0.}./[0-9]+ 
00e0: 66 72 65 65 20 2f 20 7b 0a 20 20 69 66 20 28 6d  free / {.  if (m
00f0: 65 6d 5b 24 36 5d 3d 3d 22 22 29 20 7b 0a 20 20  em[$6]=="") {.  
0100: 20 20 70 72 69 6e 74 20 22 2a 2a 2a 20 66 72 65    print "*** fre
0110: 65 20 77 69 74 68 6f 75 74 20 61 20 6d 61 6c 6c  e without a mall
0120: 6f 63 20 61 74 22 2c 24 36 0a 20 20 7d 0a 20 20  oc at",$6.  }.  
0130: 6d 65 6d 5b 24 36 5d 20 3d 20 22 22 3b 0a 20 20  mem[$6] = "";.  
0140: 73 74 72 5b 24 36 5d 20 3d 20 22 22 0a 7d 0a 2f  str[$6] = "".}./
0150: 5e 73 74 72 69 6e 67 20 61 74 20 2f 20 7b 0a 20  ^string at / {. 
0160: 20 61 64 64 72 20 3d 20 24 34 0a 20 20 73 75 62   addr = $4.  sub
0170: 28 22 73 74 72 69 6e 67 20 61 74 20 22 20 61 64  ("string at " ad
0180: 64 72 20 22 20 69 73 20 22 2c 22 22 29 0a 20 20  dr " is ","").  
0190: 73 74 72 5b 61 64 64 72 5d 20 3d 20 24 30 0a 7d  str[addr] = $0.}
01a0: 0a 45 4e 44 20 7b 0a 20 20 66 6f 72 28 61 64 64  .END {.  for(add
01b0: 72 20 69 6e 20 6d 65 6d 29 7b 0a 20 20 20 20 69  r in mem){.    i
01c0: 66 28 20 6d 65 6d 5b 61 64 64 72 5d 3d 3d 22 22  f( mem[addr]==""
01d0: 20 29 20 63 6f 6e 74 69 6e 75 65 0a 20 20 20 20   ) continue.    
01e0: 70 72 69 6e 74 20 6d 65 6d 5b 61 64 64 72 5d 2c  print mem[addr],
01f0: 20 73 74 72 5b 61 64 64 72 5d 0a 20 20 7d 0a 7d   str[addr].  }.}
0200: 0a                                               .