File: xleaktrace

package info (click to toggle)
bash 4.3-11%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 37,652 kB
  • ctags: 18,453
  • sloc: ansic: 99,503; sh: 6,836; yacc: 5,032; perl: 4,227; makefile: 4,197; asm: 48; awk: 23; sed: 16
file content (47 lines) | stat: -rwxr-xr-x 968 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /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
#
# Copyright (c) 2001 Chester Ramey
# Permission is hereby granted to deal in this Software without restriction.
# THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
#
# 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];
		}
	}
}