| Line | |
|---|
| 1 | #! /usr/bin/awk -f
|
|---|
| 2 | #
|
|---|
| 3 | # xleaktrace - print unfreed memory using input generated by compact malloc
|
|---|
| 4 | # tracing (malloc_set_trace(1))
|
|---|
| 5 | #
|
|---|
| 6 | # NOTE: we ignore `realloc' tags because they're just extra information
|
|---|
| 7 | #
|
|---|
| 8 | # Chet Ramey
|
|---|
| 9 | # chet@po.cwru.edu
|
|---|
| 10 | #
|
|---|
| 11 | BEGIN {
|
|---|
| 12 | FS=":";
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | $1 == "alloc" {
|
|---|
| 16 | alloc[$2] = 1;
|
|---|
| 17 |
|
|---|
| 18 | size[$2] = $3;
|
|---|
| 19 | file[$2] = $4;
|
|---|
| 20 | line[$2] = $5;
|
|---|
| 21 |
|
|---|
| 22 | # printf "allocated: %s %d %d %s %d\n", $2, alloc[$2], size[$2], file[$2], line[$2];
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | $1 == "free" {
|
|---|
| 26 | if ($2 in alloc) {
|
|---|
| 27 | alloc[$2] = 0;
|
|---|
| 28 | # printf "freed: %s %d\n", $2, alloc[$2];
|
|---|
| 29 | } else
|
|---|
| 30 | printf "freeing unallocated pointer: %s\n", $2;
|
|---|
| 31 |
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | END {
|
|---|
| 35 | printf "unfreed memory\n";
|
|---|
| 36 | for (ptr in alloc) {
|
|---|
| 37 | if (alloc[ptr] == 1) {
|
|---|
| 38 | printf "%s (%d) from %s:%d\n", ptr, size[ptr], file[ptr], line[ptr];
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.