-
-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Malloc debug hooks: display memory block traceback on error #70751
Comments
Python implements debug hooks on Python memory allocators: Problem: buffer understand and buffer overflow are only detected when a memory block is released, which may occur far from the code responsible to create the buffer. Attached patch dumps the traceback where a memory block was allocated on error in malloc debug hooks. The feature requires to enable tracemalloc to record tracebacks. test.py used in below example: import _testcapi
def f():
_testcapi.pymem_buffer_overflow()
f() Example: Memory block traceback (most recent call first): Fatal Python error: bad trailing pad byte Current thread 0x00007f4a93d9c700 (most recent call first): The patch adds the "Memory block traceback" section. |
See also the issue bpo-26567: "Use tracemalloc to display the traceback where an object was allocated when a ResourceWarning is emitted". |
I reviewed my own patch on Rietveld :-) |
New changeset 18a19e62bac5 by Victor Stinner in branch 'default': New changeset fea3c6e9a38e by Victor Stinner in branch '3.5': |
New changeset cef6a32d805f by Victor Stinner in branch 'default': |
New changeset 8215dae7ec3c by Victor Stinner in branch 'default': |
New changeset 769dfcb701ee by Victor Stinner in branch 'default': |
FYI Victor if you haven’t already noticed, the Windows buildbots are choking on a variable-length array: ..\Python\traceback.c(513): error C2057: expected constant expression [D:\buildarea\3.x.bolen-windows10\build\PCbuild\pythoncore.vcxproj] |
New changeset 5f2284ecf9c6 by Victor Stinner in branch 'default': |
Martin Panter added the comment:
Thank you, sometimes I miss buildbot failures. I pushed changes which had 2 tests, so I knew that all buildbots were For Windows, it's a pity, the expression is constant. Stupid compiler I will check again if buildbots are now happy with the current code ;-) |
Ok, buildbots are green again. I close the issue. |
New changeset 7b079adb0774 by Victor Stinner in branch 'default': |
I'm reopening this to commit a fix for a comment which became obsolete following this change: https://hg.python.org/cpython/rev/18a19e62bac5. |
I am wondering why 53/22? 5/2 is as good for 8-bytes long -- both gives 21-bytes buffer. I do not propose to change anything. It is just curiosity. |
53/22 is closer to math.log(256)/math.log(10) than 5/2, and 8*53 should not overflow :-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: