forked from taihegames/libpitaya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_leaks.py
executable file
·42 lines (30 loc) · 993 Bytes
/
check_leaks.py
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
#!/usr/bin/env python3
import sys
import os
import xml.etree.ElementTree
if len(sys.argv) != 2:
print('Usage: ./check-leaks.py <xml-file>')
exit(1)
filepath = sys.argv[1]
if not os.path.exists(filepath):
print('The file {} does not exist.'.format(filepath))
exit(1)
e = xml.etree.ElementTree.parse(filepath).getroot()
errors = e.findall('error')
print('================ Valgrind output ({} errors) ================'.format(len(errors)))
leaks = []
possible_leaks = []
for err in errors:
kind = err.findall('kind')[0]
if kind.text == 'Leak_DefinitelyLost':
leaks.append(err)
elif kind.text == 'Leak_PossiblyLost':
possible_leaks.append(err)
num_leaks = len(leaks)
num_possible_leaks = len(possible_leaks)
print('Leaks'.format(len(leaks)))
print(' * certain: {}'.format(num_leaks))
print(' * possible: {}'.format(num_possible_leaks))
print('==============================================================')
if num_leaks > 0:
exit(1)