Debian Codegraph @

tools/debug/core/error_ref_leak.py

raw
1 #!/usr/bin/env python3
2 #
3 # Copyright 2017 gRPC authors.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Reads stdin to find error_refcount log lines, and prints reference leaks
18 # to stdout
19
20 # usage: python error_ref_leak < logfile.txt
21
22 import re
23 import sys
24
25 data = sys.stdin.readlines()
26
27 errs = []
28 for line in data:
29 # if we care about the line
30 if re.search(r'error.cc', line):
31 # str manip to cut off left part of log line
32 line = line.partition('error.cc:')[-1]
33 line = re.sub(r'\d+] ', r'', line)
34 line = line.strip().split()
35 err = line[0].strip(":")
36 if line[1] == "create":
37 assert (err not in errs)
38 errs.append(err)
39 elif line[0] == "realloc":
40 errs.remove(line[1])
41 errs.append(line[3])
42 # explicitly look for the last dereference
43 elif line[1] == "1" and line[3] == "0":
44 assert (err in errs)
45 errs.remove(err)
46
47 print(("leaked:", errs))