Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix memory error
  • Loading branch information
eendebakpt committed Nov 29, 2024
commit 8ef7a04d7f94d2a0cd63f3ae9176ca53c7a2f65b
5 changes: 3 additions & 2 deletions Modules/_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1649,9 +1649,8 @@ static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
memcpy(mc->vectorcall_args, PySequence_Fast_ITEMS(args),
nargs * sizeof(PyObject*));
}
if (kwds) {
if (kwds && PyDict_Size(kwds)) {
const Py_ssize_t nkwds = PyDict_Size(kwds);

mc->vectorcall_kwnames = PyTuple_New(nkwds);
if (!mc->vectorcall_kwnames) {
return -1;
Expand Down Expand Up @@ -1712,6 +1711,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
mc->kwds = Py_XNewRef(kwds);
mc->vectorcall = NULL;
mc->vectorcall_args = NULL;
mc->vectorcall_kwnames = NULL;

Py_ssize_t vectorcall_size = PyTuple_GET_SIZE(args)
+ (kwds ? PyDict_Size(kwds) : 0);
Expand All @@ -1735,6 +1735,7 @@ methodcaller_clear(methodcallerobject *mc)
Py_CLEAR(mc->kwds);
if (mc->vectorcall_args != NULL) {
PyMem_Free(mc->vectorcall_args);
mc->vectorcall_args = NULL;
Py_CLEAR(mc->vectorcall_kwnames);
}
}
Expand Down