# HG changeset patch # User Julien Cristau # Date 1363638841 -3600 # Node ID ff11ac645d9a84ccda09a2fc975c4933dacf33e9 # Parent d801be922dc2cd24d59803abf4957834fd1f352e Fix sys.getallocatedblocks() when running on valgrind _Py_AllocatedBlocks was never incremented in PyObject_Malloc(), but would still be decremented on failure or in PyObject_Free(). diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c --- 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).