summaryrefslogtreecommitdiff
path: root/Objects/obmalloc.c
diff options
context:
space:
mode:
authorT. Wouters <thomas@python.org>2017-03-31 10:10:19 -0700
committerGitHub <noreply@github.com>2017-03-31 10:10:19 -0700
commit06bb4873d6a9ac303701d08a851d6cd9a51e02a3 (patch)
tree9702ec5165c8b180226b8932566137873709c7d9 /Objects/obmalloc.c
parenta00c3fd12d421e41b769debd7df717d17b0deed5 (diff)
downloadcpython-git-06bb4873d6a9ac303701d08a851d6cd9a51e02a3.tar.gz
Fix spurious MemoryError introduced by PR #886. (#930)
Fix MemoryError caused by moving around code in PR #886; nbytes was sometimes used unitinitalized (in non-debug builds, when use_calloc was false and elsize was 0).
Diffstat (limited to 'Objects/obmalloc.c')
-rw-r--r--Objects/obmalloc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index f284d9fc0a..32e7ecbe1e 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -1227,10 +1227,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
_Py_AllocatedBlocks++;
- if (nelem == 0 || elsize == 0)
- goto redirect;
-
- assert(nelem <= PY_SSIZE_T_MAX / elsize);
+ assert(elsize == 0 || nelem <= PY_SSIZE_T_MAX / elsize);
nbytes = nelem * elsize;
#ifdef WITH_VALGRIND
@@ -1240,6 +1237,9 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
goto redirect;
#endif
+ if (nelem == 0 || elsize == 0)
+ goto redirect;
+
if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) {
LOCK();
/*