From aadf057bf40bcb3e3b5a1ec3294b892630ae47bf Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sun, 6 Nov 2022 06:04:36 -0800 Subject: [PATCH] gh-83004: Clean up refleak in _zoneinfo initialisation (GH-98842) (cherry picked from commit 31f2f6568d89564cc1d686cd6b75ba5578aaa748) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- .../Library/2022-11-02-05-54-02.gh-issue-83004.0v8iyw.rst | 1 + Modules/_zoneinfo.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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..bd54d3eae8c908 --- /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 1535721b026d1f..55975f4e269109 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -2652,8 +2652,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");