From b3f0c8335fd8e3c436d7141400a662d9aa9d9085 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Nov 2020 14:48:58 +0100 Subject: [PATCH] bpo-40998: Fix a refleak in create_filter() --- Python/_warnings.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Python/_warnings.c b/Python/_warnings.c index 8d33fbe0f878b8..313420c63148f4 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -69,12 +69,14 @@ create_filter(PyObject *category, _Py_Identifier *id, const char *modname) return NULL; } } else { - modname_obj = Py_None; + modname_obj = Py_NewRef(Py_None); } /* This assumes the line number is zero for now. */ - return PyTuple_Pack(5, action_str, Py_None, - category, modname_obj, _PyLong_GetZero()); + PyObject *filter = PyTuple_Pack(5, action_str, Py_None, + category, modname_obj, _PyLong_GetZero()); + Py_DECREF(modname_obj); + return filter; } #endif