From 2b3c96811e3fda017dd2b6f17d34337c05a5b7f2 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Mon, 16 Mar 2020 03:37:49 +0800 Subject: [PATCH] Fix a possible refleak in tupleobject.c (GH-19018) (cherry picked from commit c81609e44eed641d3b8a137daa31ef35501c1f85) Co-authored-by: Hai Shi --- Objects/tupleobject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 7ee06e20e4a913..2a1b8fad98dbb0 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -696,8 +696,10 @@ tuple_subtype_new(PyTypeObject *type, PyObject *iterable) return NULL; assert(PyTuple_Check(tmp)); newobj = type->tp_alloc(type, n = PyTuple_GET_SIZE(tmp)); - if (newobj == NULL) + if (newobj == NULL) { + Py_DECREF(tmp); return NULL; + } for (i = 0; i < n; i++) { item = PyTuple_GET_ITEM(tmp, i); Py_INCREF(item);