Skip to content

Commit 59de618

Browse files
author
Magne Hov
committed
fixup! Add malloc free leak detector scripts
1 parent fa19d0e commit 59de618

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

_linters/mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ python_version = 3.6
44
[mypy-undodb.debugger_extensions]
55
ignore_missing_imports = True
66

7+
[mypy-undodb.debugger_extensions.debugger_io]
8+
ignore_missing_imports = True
9+
710
[mypy-undodb.udb_launcher]
811
ignore_missing_imports = True
912

malloc_free_check/malloc-free.py renamed to malloc_free_check/malloc-free-check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from undo.udb_launcher import REDIRECTION_COLLECT, UdbLauncher
1515

1616

17-
def main(argv):
17+
def main(argv: list[str]) -> None:
1818
# Get the arguments from the command line.
1919
try:
2020
recording = argv[1]
@@ -34,7 +34,7 @@ def main(argv):
3434
# to the user but, in case of errors, we want to display it.
3535
res = launcher.run_debugger(redirect_debugger_output=REDIRECTION_COLLECT)
3636

37-
if res.exit_code == 0:
37+
if not res.exit_code:
3838
# All good as UDB exited with exit code 0 (i.e. no errors).
3939
# The result_data attribute is used to pass information from the extension to this script.
4040
unmatched = res.result_data["unmatched"]

malloc_free_check/malloc_free_check_extension.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from undodb.debugger_extensions.debugger_io import redirect_to_launcher_output
1717

1818

19-
def leak_check():
19+
def leak_check() -> None:
2020
"""
2121
Implements breakpoints and stops on all calls to malloc() and free(), capturing the
2222
timestamp, size and returned pointer for malloc(), then confirms the address pointer is later
@@ -83,15 +83,14 @@ def leak_check():
8383
else:
8484
print("--- INFO: Free called with null address")
8585

86-
#with redirect_to_launcher_output():
86+
# with redirect_to_launcher_output():
8787
print(f"{time}: free() called for {int(addr):#x}")
8888

89-
9089
# If Allocations has any entries remaining, they were not released.
9190
with redirect_to_launcher_output():
92-
print ()
93-
print (f"{len(allocations)} unmatched memory allocation(s):")
94-
print ()
91+
print()
92+
print(f"{len(allocations)} unmatched memory allocation(s):")
93+
print()
9594

9695
total = 0
9796

@@ -124,7 +123,7 @@ def leak_check():
124123

125124
# UDB will automatically load the modules passed to UdbLauncher.add_extension and, if present,
126125
# automatically execute any function (with no arguments) called "run".
127-
def run():
126+
def run() -> None:
128127
# Needed to allow GDB to fixup breakpoints properly after glibc has been loaded
129128
gdb.Breakpoint("main")
130129

0 commit comments

Comments
 (0)