error_ref_leak.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. # Reads stdin to find error_refcount log lines, and prints reference leaks
  17. # to stdout
  18. # usage: python error_ref_leak < logfile.txt
  19. import re
  20. import sys
  21. data = sys.stdin.readlines()
  22. errs = []
  23. for line in data:
  24. # if we care about the line
  25. if re.search(r'error.cc', line):
  26. # str manip to cut off left part of log line
  27. line = line.partition('error.cc:')[-1]
  28. line = re.sub(r'\d+] ', r'', line)
  29. line = line.strip().split()
  30. err = line[0].strip(":")
  31. if line[1] == "create":
  32. assert (err not in errs)
  33. errs.append(err)
  34. elif line[0] == "realloc":
  35. errs.remove(line[1])
  36. errs.append(line[3])
  37. # explicitly look for the last dereference
  38. elif line[1] == "1" and line[3] == "0":
  39. assert (err in errs)
  40. errs.remove(err)
  41. print(("leaked:", errs))