summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2020-01-27 15:02:23 (GMT)
committerPablo Galindo <Pablogsal@gmail.com>2020-01-27 15:02:23 (GMT)
commit4dbf2d8c6789a9b7299b142033073213604b8fdc (patch)
tree1390368a570c1d528c18df15bf74ec443451f04d /Objects/listobject.c
parenta46575a8f2ded8b49e26c25bb67192e1500e76ca (diff)
downloadcpython-4dbf2d8c6789a9b7299b142033073213604b8fdc.zip
cpython-4dbf2d8c6789a9b7299b142033073213604b8fdc.tar.gz
cpython-4dbf2d8c6789a9b7299b142033073213604b8fdc.tar.bz2
bpo-39453: Make list.__contains__ hold strong references to avoid crashes (GH-18181)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index a4e90db..38055d5 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -445,11 +445,16 @@ list_length(PyListObject *a)
static int
list_contains(PyListObject *a, PyObject *el)
{
+ PyObject *item;
Py_ssize_t i;
int cmp;
- for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
+ for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i) {
+ item = PyList_GET_ITEM(a, i);
+ Py_INCREF(item);
cmp = PyObject_RichCompareBool(PyList_GET_ITEM(a, i), el, Py_EQ);
+ Py_DECREF(item);
+ }
return cmp;
}