Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce77fe4

Browse files
Fix bug in malloc case
1 parent 50c92d0 commit ce77fe4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Python/ceval.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,12 @@ _PyObjectArray_FromStackRefArray(_PyStackRef *input, Py_ssize_t nargs, PyObject
702702
{
703703
PyObject **result;
704704
if (nargs > MAX_STACKREF_SCRATCH) {
705-
result = PyMem_Malloc(nargs * sizeof(PyObject *));
705+
// +1 in case PY_VECTORCALL_ARGUMENTS_OFFSET is set.
706+
result = PyMem_Malloc((nargs + 1) * sizeof(PyObject *));
706707
if (result == NULL) {
707708
return NULL;
708709
}
710+
result++;
709711
}
710712
else {
711713
result = scratch;

Python/ceval_macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ do { \
469469
#ifdef Py_GIL_DISABLED
470470
#define STACKREFS_TO_PYOBJECTS_CLEANUP(NAME) \
471471
/* +1 because we +1 previously */ \
472-
_PyObjectArray_Free(NAME, NAME##_temp + 1);
472+
_PyObjectArray_Free(NAME - 1, NAME##_temp);
473473
#else
474474
#define STACKREFS_TO_PYOBJECTS_CLEANUP(NAME) \
475475
(void)(NAME);

0 commit comments

Comments
 (0)