31directory =
"../src/iop/"
33alloc_regex =
r"([a-zA-Z0-9_\->\.\[\]]+) = (dt_|c|m|dt_opencl_)alloc.*\(.+\)"
38 f = open(os.path.join(directory, file),
"r")
44 print(
"\t\t line", line_number,
":", elem.strip())
48for file
in sorted(os.listdir(directory)):
49 if file.endswith(
".c")
or file.endswith(
".h"):
50 f = open(os.path.join(directory, file),
"r")
54 matches = re.finditer(alloc_regex, content, re.MULTILINE)
62 for matchNum, match
in enumerate(matches):
64 variable_name = match.group(1)
65 alloc_type = match.group(2)
68 variable_alloc_regex =
" %s = %salloc.*\(.+\)" % (variable_name, alloc_type)
69 matches2 = re.findall(variable_alloc_regex, content, re.MULTILINE)
70 allocs = len(matches2)
71 matches2 = set(matches2)
74 variable_free_regex =
r""
76 if(alloc_type ==
"dt_opencl_"):
77 variable_free_regex =
".*release_mem_object.*\(%s\)" % variable_name
78 buffer_type =
"OpenCL"
80 variable_free_regex =
" \S*free.*\(%s\)" % variable_name
82 matches3 = re.findall(variable_free_regex, content, re.MULTILINE)
84 matches3 = set(matches3)
87 if(frees < allocs
and frees == 0):
88 print(
"\tERROR: %s buffer `%s` is allocated %i time(s) but never freed" % (buffer_type, variable_name, allocs))
96 elif(frees < allocs
and frees > 0):
97 print(
"\tWARNING: %s buffer `%s` is allocated %i time(s) but freed %i time(s)" % (buffer_type, variable_name, allocs, frees))
100 for elem
in matches3:
103 suspicious_allocs += 1
109 if(suspicious_allocs > 0):
111 if(faulty_allocs > 0):
114 print(
"\t%s: %i safe alloc(s) detected over %i\n" % (msg_type, safe_allocs, safe_allocs + faulty_allocs + suspicious_allocs))
find_call_and_line(elem, file, directory)