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

Skip to content

Commit f966e53

Browse files
authored
bpo-29564:_PyMem_DumpTraceback() suggests enabling tracemalloc (GH-10510)
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 474eedf commit f966e53

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
@@ -486,6 +486,8 @@ def test_buffer_overflow(self):
486486
r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
487487
r" Data at p: cb cb cb .*\n"
488488
r"\n"
489+
r"Enable tracemalloc to get the memory block allocation traceback\n"
490+
r"\n"
489491
r"Fatal Python error: bad trailing pad byte")
490492
regex = regex.format(ptr=self.PTR_REGEX)
491493
regex = re.compile(regex, flags=re.DOTALL)
@@ -500,6 +502,8 @@ def test_api_misuse(self):
500502
r" The block was made by call #[0-9]+ to debug malloc/realloc.\n"
501503
r" Data at p: cb cb cb .*\n"
502504
r"\n"
505+
r"Enable tracemalloc to get the memory block allocation traceback\n"
506+
r"\n"
503507
r"Fatal Python error: bad ID: Allocated using API 'm', verified using API 'r'\n")
504508
regex = regex.format(ptr=self.PTR_REGEX)
505509
self.assertRegex(out, regex)

Modules/_tracemalloc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,12 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
14711471
traceback_t *traceback;
14721472
int i;
14731473

1474+
if (!_Py_tracemalloc_config.tracing) {
1475+
PUTS(fd, "Enable tracemalloc to get the memory block "
1476+
"allocation traceback\n\n");
1477+
return;
1478+
}
1479+
14741480
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
14751481
if (traceback == NULL)
14761482
return;

0 commit comments

Comments
 (0)
0