From 31f2f6568d89564cc1d686cd6b75ba5578aaa748 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: gh-83004: Clean up refleak in _zoneinfo initialisation (#98842) --- .../next/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 0000000..bd54d3e --- /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 36b25bf..9986b91 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -2657,8 +2657,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 */ _tzpath_find_tzfile = -- cgit v0.12