summaryrefslogtreecommitdiffstats
path: root/scratch/bash-3.1-postpatch/lib/malloc/xleaktrace
diff options
context:
space:
mode:
Diffstat (limited to 'scratch/bash-3.1-postpatch/lib/malloc/xleaktrace')
-rwxr-xr-xscratch/bash-3.1-postpatch/lib/malloc/xleaktrace43
1 files changed, 43 insertions, 0 deletions
diff --git a/scratch/bash-3.1-postpatch/lib/malloc/xleaktrace b/scratch/bash-3.1-postpatch/lib/malloc/xleaktrace
new file mode 100755
index 0000000..573437c
--- /dev/null
+++ b/scratch/bash-3.1-postpatch/lib/malloc/xleaktrace
@@ -0,0 +1,43 @@
+#! /usr/bin/awk -f
+#
+# xleaktrace - print unfreed memory using input generated by compact malloc
+# tracing (malloc_set_trace(1))
+#
+# NOTE: we ignore `realloc' tags because they're just extra information
+#
+# Chet Ramey
+# chet@po.cwru.edu
+#
+BEGIN {
+ FS=":";
+}
+
+$1 == "alloc" {
+ alloc[$2] = 1;
+
+ size[$2] = $3;
+ file[$2] = $4;
+ line[$2] = $5;
+
+# printf "allocated: %s %d %d %s %d\n", $2, alloc[$2], size[$2], file[$2], line[$2];
+ }
+
+$1 == "free" {
+ if ($2 in alloc) {
+ alloc[$2] = 0;
+# printf "freed: %s %d\n", $2, alloc[$2];
+ } else
+ printf "freeing unallocated pointer: %s\n", $2;
+
+ }
+
+END {
+ printf "unfreed memory\n";
+ for (ptr in alloc) {
+ if (alloc[ptr] == 1) {
+ printf "%s (%d) from %s:%d\n", ptr, size[ptr], file[ptr], line[ptr];
+ }
+ }
+}
+
+