-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup_check7.stp
80 lines (71 loc) · 2.3 KB
/
cleanup_check7.stp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
global resources
global hits
global files_open_attempt
global files_close_attempt
global files_opened
probe process("./simple_resources7").function("prepare") {
hits[probefunc()]++
resources[$res] = hits[probefunc()]
}
probe process("./simple_resources7").function("cleanup") {
hits[probefunc()]++
if ([$res] in resources)
delete resources[$res]
else
printf("Attempting to clean up uninitialized Resource: %p in %d. %s call\n", $res, hits[probefunc()], probefunc())
}
probe syscall.open, syscall.openat
{
if (pid()==target()) {
files_open_attempt[pid()] = filename
}
}
probe syscall.open.return, syscall.openat.return
{
if (pid()==target()) {
filename = files_open_attempt[pid()]
delete files_open_attempt[pid()]
retval = strtol(retstr, 10)
if (retval >= 0) {
files_opened[pid(), retval] = filename
printf("%s -- %s -- successfully opened: %s (%d)\n", ctime(gettimeofday_s()), execname(), filename, retval)
} else {
printf("%s -- %s -- failed to open: %s\n", ctime(gettimeofday_s()), execname(), filename)
}
}
}
probe syscall.close
{
if (pid()==target()) {
files_close_attempt[pid()] = fd
}
}
probe syscall.close.return
{
if (pid()==target()) {
fd = files_close_attempt[pid()]
delete files_close_attempt[pid()]
retval = strtol(retstr, 10)
if (retval != -1) {
printf("%s -- %s -- successfully closed: %s (%d)\n", ctime(gettimeofday_s()), execname(), files_opened[pid(), fd], fd)
delete files_opened[pid(), fd]
} else {
printf("%s -- %s -- failed to close: %s (%d)\n", ctime(gettimeofday_s()), execname(), files_opened[pid(), fd], fd)
}
}
}
probe process("./simple_resources7").end {
dangling = 0
foreach (res_addr in resources) {
dangling++
printf("Resource %p allocated in %d. prepare call was not freed\n", res_addr, resources[res_addr])
}
foreach ([pid, fd] in files_opened) {
dangling++
printf("File %s (%d) opened by PID(%d) was not properly closed\n", files_opened[pid, fd], fd, pid)
}
if (dangling != 0)
printf("Failed: All resources not freed!\n")
else
printf("Ok: All resources correctly freed!\n")
}