8000 bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10… · python/cpython@ae88781 · GitHub
[go: up one dir, main page]

Skip to content

Commit ae88781

Browse files
authored
bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10510) (GH-10518)
If tracemalloc is not tracing Python memory allocations, _PyMem_DumpTraceback() now suggests to enable tracemalloc to get the traceback where the memory block has been allocated.
1 parent 60a6bae commit ae88781

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Lib/test/test_capi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ def test_buffer_overflow(self):
534534
r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
535535
r" Data at p: cb cb cb .*\n"
536536
r"\n"
537+
r"Enable tracemalloc to get the memory block allocation traceback\n"
538+
r"\n"
537539
r"Fatal Python error: bad trailing pad byte")
538540
regex = regex.format(ptr=self.PTR_REGEX)
539541
regex = re.compile(regex, flags=re.DOTALL)
@@ -548,6 +550,8 @@ def test_api_misuse(self):
548550
r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
549551
r" Data at p: cb cb cb .*\n"
550552
r"\n"
553+
r"Enable tracemalloc to get the memory block allocation traceback\n"
554+
r"\n"
551555
r"Fatal Python error: bad ID: Allocated using API 'm', verified using API 'r'\n")
552556
regex = regex.format(ptr=self.PTR_REGEX)
553557
self.assertRegex(out, regex)

Modules/_tracemalloc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,12 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
14921492
traceback_t *traceback;
14931493
int i;
14941494

1495+
if (!tracemalloc_config.tracing) {
1496+
PUTS(fd, "Enable tracemalloc to get the memory block "
1497+
"allocation traceback\n\n");
1498+
return;
1499+
}
1500+
14951501
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
14961502
if (traceback == NULL)
14971503
return;

0 commit comments

Comments
 (0)
0