diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-07 23:53:10 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-07 23:53:10 -0400 |
| commit | 1d828c8debab274f7b058e3474e2494dfccb0c19 (patch) | |
| tree | 4fe4d248cfa56849199e91e088b9e838b8ad801e | |
| parent | 66788e6edb8a7e59f5676ca8cf928e23583cb31a (diff) | |
Added an awk script to check for leaks in the memory logging output we just added.
| -rw-r--r-- | new/leaks.awk | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/new/leaks.awk b/new/leaks.awk new file mode 100644 index 0000000..1d19ea8 --- /dev/null +++ b/new/leaks.awk @@ -0,0 +1,56 @@ +# 7 april 2015 + +$2 == "alloc" { + if ($1 in A) { + problem($1 " already allocated (" A[$1] "); allocated at " NR) + next + } + A[$1] = type() + next +} + +$2 == "realloc" { + if (!($1 in A)) { + problem($1 " not yet allocated; reallocated at " NR) + next + } + if ($3 in A) { + problem($3 " already allocated (" A[$3] "); reallocated at " NR) + next + } + t = A[$1] + delete A[$1] + A[$3] = t + next +} + +$2 == "free" { + if (!($1 in A)) { + problem($1 " not yet allocated; freed at " NR) + next + } + delete A[$1] + next +} + +{ problem("unrecognized line " $0 " at " NR) } + +END { + for (i in A) + problem("leaked " A[i] " at " i) + close("/dev/stderr") + if (hasProblems) + exit 1 +} + +function problem(s) { + print s > "/dev/stderr" + hasProblems = 1 +} + +function type( s, i) { + s = $3 + for (i = 4; i <= NF; i++) + s = s " " $i + return s +} |
