From 7924bd62f1ce2116dc573f8be51ebf84c8c57a6a Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Tue, 30 May 2023 17:27:55 +0800 Subject: [PATCH] gh-102251: Fix reference leak in _testsinglephase initialization (GH-105082) Correctly decref 'initialized' in init_module() (cherry picked from commit d14eb3433cf2a40a202471b815f0a935f2840ead) Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Co-authored-by: Erlend E. Aasland --- Modules/_testsinglephase.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/_testsinglephase.c b/Modules/_testsinglephase.c index a16157702ae789..8e6973f0b052cc 100644 --- a/Modules/_testsinglephase.c +++ b/Modules/_testsinglephase.c @@ -140,7 +140,9 @@ init_module(PyObject *module, module_state *state) if (initialized == NULL) { return -1; } - if (PyModule_AddObjectRef(module, "_module_initialized", initialized) != 0) { + int rc = PyModule_AddObjectRef(module, "_module_initialized", initialized); + Py_DECREF(initialized); + if (rc < 0) { return -1; }