summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorJeroen Demeyer <J.Demeyer@UGent.be>2019-05-22 14:52:13 +0200
committerPetr Viktorin <pviktori@redhat.com>2019-05-22 14:52:13 +0200
commitd092caf096fa48baadfc0900792206bb5aa0192d (patch)
treeabf22ad34897b4715b6f80d511aff99bf1ea9375 /Objects
parent791e5fcbab9e444b62d13d08707cbbbeb9406297 (diff)
downloadcpython-git-d092caf096fa48baadfc0900792206bb5aa0192d.tar.gz
bpo-36907: fix refcount bug in _PyStack_UnpackDict() (GH-13381) (GH-13493)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/call.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Objects/call.c b/Objects/call.c
index e6076e7005..1209ed3977 100644
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -542,10 +542,14 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self,
}
result = (*fastmeth) (self, stack, nargs, kwnames);
- if (stack != args) {
+ if (kwnames != NULL) {
+ Py_ssize_t i, n = nargs + PyTuple_GET_SIZE(kwnames);
+ for (i = 0; i < n; i++) {
+ Py_DECREF(stack[i]);
+ }
PyMem_Free((PyObject **)stack);
+ Py_DECREF(kwnames);
}
- Py_XDECREF(kwnames);
break;
}
@@ -1379,8 +1383,11 @@ _PyStack_UnpackDict(PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs,
return -1;
}
- /* Copy position arguments (borrowed references) */
- memcpy(stack, args, nargs * sizeof(stack[0]));
+ /* Copy positional arguments */
+ for (i = 0; i < nargs; i++) {
+ Py_INCREF(args[i]);
+ stack[i] = args[i];
+ }
kwstack = stack + nargs;
pos = i = 0;
@@ -1389,8 +1396,8 @@ _PyStack_UnpackDict(PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs,
called in the performance critical hot code. */
while (PyDict_Next(kwargs, &pos, &key, &value)) {
Py_INCREF(key);
+ Py_INCREF(value);
PyTuple_SET_ITEM(kwnames, i, key);
- /* The stack contains borrowed references */
kwstack[i] = value;
i++;
}