Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add malloc free leak detector scripts #59

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! Add malloc free leak detector scripts
Magne Hov committed Mar 13, 2025
commit 59de618ed200d11e11b93df564d5b649a48c336c
3 changes: 3 additions & 0 deletions _linters/mypy.ini
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ python_version = 3.6
[mypy-undodb.debugger_extensions]
ignore_missing_imports = True

[mypy-undodb.debugger_extensions.debugger_io]
ignore_missing_imports = True

[mypy-undodb.udb_launcher]
ignore_missing_imports = True

Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
from undo.udb_launcher import REDIRECTION_COLLECT, UdbLauncher


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

if res.exit_code == 0:
if not res.exit_code:
# All good as UDB exited with exit code 0 (i.e. no errors).
# The result_data attribute is used to pass information from the extension to this script.
unmatched = res.result_data["unmatched"]
13 changes: 6 additions & 7 deletions malloc_free_check/malloc_free_check_extension.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
from undodb.debugger_extensions.debugger_io import redirect_to_launcher_output
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two should be from undo.[...]. The undodb name was deprecated a while ago.



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

#with redirect_to_launcher_output():
# with redirect_to_launcher_output():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this commented out line?

print(f"{time}: free() called for {int(addr):#x}")


# If Allocations has any entries remaining, they were not released.
with redirect_to_launcher_output():
print ()
print (f"{len(allocations)} unmatched memory allocation(s):")
print ()
print()
print(f"{len(allocations)} unmatched memory allocation(s):")
print()

total = 0

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

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