[Python-checkins] gh-83004: Clean up refleak in _zoneinfo initialisation (GH-98842)

miss-islington webhook-mailer at python.org
Sun Nov 6 09:38:49 EST 2022


https://github.com/python/cpython/commit/70006d6a5ff4492f02625ac995dba5f58940a0ea
commit: 70006d6a5ff4492f02625ac995dba5f58940a0ea
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-11-06T06:38:26-08:00
summary:

gh-83004: Clean up refleak in _zoneinfo initialisation (GH-98842)

(cherry picked from commit 31f2f6568d89564cc1d686cd6b75ba5578aaa748)

Co-authored-by: Shantanu <12621235+hauntsaninja at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst
M Modules/_zoneinfo.c

diff --git a/Misc/NEWS.d/next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst b/Misc/NEWS.d/next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst
new file mode 100644
index 000000000000..bd54d3eae8c9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst
@@ -0,0 +1 @@
+Clean up refleak on failed module initialisation in :mod:`_zoneinfo`
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index 0388d27ce10a..836d1cfd60bf 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -2648,8 +2648,9 @@ zoneinfomodule_exec(PyObject *m)
         goto error;
     }
 
-    Py_INCREF(&PyZoneInfo_ZoneInfoType);
-    PyModule_AddObject(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType);
+    if (PyModule_AddObjectRef(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType) < 0) {
+        goto error;
+    }
 
     /* Populate imports */
     PyObject *_tzpath_module = PyImport_ImportModule("zoneinfo._tzpath");



More information about the Python-checkins mailing list