Skip to content

Commit a610d9f

Browse files
INCREF type before calling __index__
1 parent 4b1f1ac commit a610d9f

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Objects/typeobject.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9715,18 +9715,25 @@ wrap_indexargfunc(PyObject *self, PyObject *args, void *wrapped)
97159715
PyObject* o;
97169716
Py_ssize_t i;
97179717
PyTypeObject *type_before = Py_TYPE(self);
9718+
Py_INCREF(type_before);
97189719

9719-
if (!check_num_args(args, 1))
9720+
if (!check_num_args(args, 1)){
9721+
Py_DECREF(type_before);
97209722
return NULL;
9723+
}
97219724
o = PyTuple_GET_ITEM(args, 0);
97229725
i = PyNumber_AsSsize_t(o, PyExc_OverflowError);
9723-
if (i == -1 && PyErr_Occurred())
9726+
if (i == -1 && PyErr_Occurred()){
9727+
Py_DECREF(type_before);
97249728
return NULL;
9729+
}
97259730
if (Py_TYPE(self) != type_before) {
9731+
Py_DECREF(type_before);
97269732
PyErr_SetString(PyExc_TypeError,
97279733
"object mutated during numeric operation");
97289734
return NULL;
97299735
}
9736+
Py_DECREF(type_before);
97309737
return (*func)(self, i);
97319738
}
97329739

0 commit comments

Comments
 (0)