Skip to content

Commit fe0a3c1

Browse files
committed
Issue #17469: Fix _Py_GetAllocatedBlocks() and sys.getallocatedblocks() when running on valgrind.
1 parent 7bfea66 commit fe0a3c1

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #17469: Fix _Py_GetAllocatedBlocks() and sys.getallocatedblocks()
14+
when running on valgrind.
15+
1316
- Issue #17619: Make input() check for Ctrl-C correctly on Windows.
1417

1518
- Issue #17357: Add missing verbosity messages for -v/-vv that were lost during

Objects/obmalloc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ PyObject_Malloc(size_t nbytes)
778778
poolp next;
779779
uint size;
780780

781+
_Py_AllocatedBlocks++;
782+
781783
#ifdef WITH_VALGRIND
782784
if (UNLIKELY(running_on_valgrind == -1))
783785
running_on_valgrind = RUNNING_ON_VALGRIND;
@@ -791,10 +793,10 @@ PyObject_Malloc(size_t nbytes)
791793
* things without checking for overflows or negatives.
792794
* As size_t is unsigned, checking for nbytes < 0 is not required.
793795
*/
794-
if (nbytes > PY_SSIZE_T_MAX)
796+
if (nbytes > PY_SSIZE_T_MAX) {
797+
_Py_AllocatedBlocks--;
795798
return NULL;
796-
797-
_Py_AllocatedBlocks++;
799+
}
798800

799801
/*
800802
* This implicitly redirects malloc(0).

0 commit comments

Comments
 (0)