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

Skip to content

Commit ef03ccd

Browse files
authored
[mypyc] Incref items before releasing tuple (#21245)
1 parent 3c3065c commit ef03ccd

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

mypyc/lib-rt/dict_ops.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ tuple_T4CIOO CPyDict_NextItem(PyObject *dict_or_iter, CPyTagged offset) {
408408
if (item == NULL || !PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 2) {
409409
if (item != NULL) {
410410
PyErr_SetString(PyExc_TypeError, "a tuple of length 2 expected");
411+
Py_DECREF(item);
411412
}
412413
ret.f0 = 0;
413414
ret.f2 = Py_None;
@@ -416,7 +417,10 @@ tuple_T4CIOO CPyDict_NextItem(PyObject *dict_or_iter, CPyTagged offset) {
416417
ret.f0 = 1;
417418
ret.f2 = PyTuple_GET_ITEM(item, 0);
418419
ret.f3 = PyTuple_GET_ITEM(item, 1);
420+
Py_INCREF(ret.f2);
421+
Py_INCREF(ret.f3);
419422
Py_DECREF(item);
423+
return ret;
420424
}
421425
}
422426
// PyDict_Next() returns borrowed references.

0 commit comments

Comments
 (0)