Skip to content

Commit 06bb487

Browse files
authored
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).
1 parent a00c3fd commit 06bb487

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Objects/obmalloc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
12271227

12281228
_Py_AllocatedBlocks++;
12291229

1230-
if (nelem == 0 || elsize == 0)
1231-
goto redirect;
1232-
1233-
assert(nelem <= PY_SSIZE_T_MAX / elsize);
1230+
assert(elsize == 0 || nelem <= PY_SSIZE_T_MAX / elsize);
12341231
nbytes = nelem * elsize;
12351232

12361233
#ifdef WITH_VALGRIND
@@ -1240,6 +1237,9 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
12401237
goto redirect;
12411238
#endif
12421239

1240+
if (nelem == 0 || elsize == 0)
1241+
goto redirect;
1242+
12431243
if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) {
12441244
LOCK();
12451245
/*

0 commit comments

Comments
 (0)