From 0aaaa62200d0bae0b79e578234ab74741da4dad3 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 6 Apr 2013 01:15:30 +0200 Subject: Issue #17469: Fix _Py_GetAllocatedBlocks() and sys.getallocatedblocks() when running on valgrind. --- Misc/NEWS | 3 +++ Objects/obmalloc.c | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index d72e8bb..f60f892 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #17469: Fix _Py_GetAllocatedBlocks() and sys.getallocatedblocks() + when running on valgrind. + - Issue #17619: Make input() check for Ctrl-C correctly on Windows. - Issue #17357: Add missing verbosity messages for -v/-vv that were lost during diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 5943f5a..3028f22 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -778,6 +778,8 @@ PyObject_Malloc(size_t nbytes) poolp next; uint size; + _Py_AllocatedBlocks++; + #ifdef WITH_VALGRIND if (UNLIKELY(running_on_valgrind == -1)) running_on_valgrind = RUNNING_ON_VALGRIND; @@ -791,10 +793,10 @@ PyObject_Malloc(size_t nbytes) * things without checking for overflows or negatives. * As size_t is unsigned, checking for nbytes < 0 is not required. */ - if (nbytes > PY_SSIZE_T_MAX) + if (nbytes > PY_SSIZE_T_MAX) { + _Py_AllocatedBlocks--; return NULL; - - _Py_AllocatedBlocks++; + } /* * This implicitly redirects malloc(0). -- cgit v0.12