From bcaa08a0fc421c3ddd91825a51b5ef9398228ac5 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Thu, 3 Nov 2022 07:29:11 -0700 Subject: [PATCH] gh-83004: Clean up refleak in _io initialisation (GH-98840) (cherry picked from commit 1208037246eeab4c5c003f1651edfefb045e6fb7) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- .../Library/2022-11-02-05-52-36.gh-issue-83004.LBl79O.rst | 1 + Modules/_io/_iomodule.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-11-02-05-52-36.gh-issue-83004.LBl79O.rst diff --git a/Misc/NEWS.d/next/Library/2022-11-02-05-52-36.gh-issue-83004.LBl79O.rst b/Misc/NEWS.d/next/Library/2022-11-02-05-52-36.gh-issue-83004.LBl79O.rst new file mode 100644 index 00000000000000..4de17abd063424 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-11-02-05-52-36.gh-issue-83004.LBl79O.rst @@ -0,0 +1 @@ +Clean up refleak on failed module initialisation in :mod:`_io`. diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 170dea41e8abdd..9e53de59c9cf73 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -718,10 +718,10 @@ PyInit__io(void) goto fail; /* BlockingIOError, for compatibility */ - Py_INCREF(PyExc_BlockingIOError); - if (PyModule_AddObject(m, "BlockingIOError", - (PyObject *) PyExc_BlockingIOError) < 0) + if (PyModule_AddObjectRef(m, "BlockingIOError", + (PyObject *) PyExc_BlockingIOError) < 0) { goto fail; + } /* Concrete base types of the IO ABCs. (the ABCs themselves are declared through inheritance in io.py)