From dfd70c5c93a0bc4f3a8021d9ba794bc4951a0491 Mon Sep 17 00:00:00 2001 From: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> Date: Tue, 30 May 2023 16:57:18 +0800 Subject: [PATCH 1/2] add missing decref in testsinglephase --- Modules/_testsinglephase.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/_testsinglephase.c b/Modules/_testsinglephase.c index a16157702ae789..6f7c9dedd06150 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; } From 587533cf98ce3a808b307e003717b5c387d5ae9a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 30 May 2023 11:00:26 +0200 Subject: [PATCH 2/2] Use idiomatic C code --- Modules/_testsinglephase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_testsinglephase.c b/Modules/_testsinglephase.c index 6f7c9dedd06150..8e6973f0b052cc 100644 --- a/Modules/_testsinglephase.c +++ b/Modules/_testsinglephase.c @@ -142,7 +142,7 @@ init_module(PyObject *module, module_state *state) } int rc = PyModule_AddObjectRef(module, "_module_initialized", initialized); Py_DECREF(initialized); - if (rc != 0) { + if (rc < 0) { return -1; }