From c982eda337ff06d2cc2563f0ce5c4b1720855af0 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 29 Oct 2022 01:25:38 -0700 Subject: [PATCH 1/4] gh-83004: Clean up refleak in _zoneinfo initialisation --- Modules/_zoneinfo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 36b25bf3c05469..9243d3ce67cbd6 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -2658,7 +2658,10 @@ zoneinfomodule_exec(PyObject *m) } Py_INCREF(&PyZoneInfo_ZoneInfoType); - PyModule_AddObject(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType); + if (PyModule_AddObject(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType) < 0) { + Py_DECREF(&PyZoneInfo_ZoneInfoType); + goto error; + } /* Populate imports */ _tzpath_find_tzfile = From d6bb764acaf850c8921bea462d522f687d343b70 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 29 Oct 2022 01:40:53 -0700 Subject: [PATCH 2/4] actually, use PyModule_AddObjectRef --- Modules/_zoneinfo.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 9243d3ce67cbd6..9986b9111177ce 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -2657,9 +2657,7 @@ zoneinfomodule_exec(PyObject *m) goto error; } - Py_INCREF(&PyZoneInfo_ZoneInfoType); - if (PyModule_AddObject(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType) < 0) { - Py_DECREF(&PyZoneInfo_ZoneInfoType); + if (PyModule_AddObjectRef(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType) < 0) { goto error; } From f9003a36fa40050fd090521048ef19ece0f5f543 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 05:54:05 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst 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 00000000000000..80d0259ec23cd7 --- /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 in :mod:`_zoneinfo` initialisation From 76634965426cdf8f02b2516e735bd7e0e990808c Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 2 Nov 2022 19:18:16 -0700 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst --- .../next/Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 80d0259ec23cd7..bd54d3eae8c908 100644 --- 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 @@ -1 +1 @@ -Clean up refleak in :mod:`_zoneinfo` initialisation +Clean up refleak on failed module initialisation in :mod:`_zoneinfo`