]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-83004: Clean up refleak in _pickle initialisation (GH-98841)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 6 Nov 2022 14:44:28 +0000 (06:44 -0800)
committerGitHub <noreply@github.com>
Sun, 6 Nov 2022 14:44:28 +0000 (06:44 -0800)
(cherry picked from commit d3b82b4463c4eb51954c0afd98342f0c5e479baa)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Misc/NEWS.d/next/Library/2022-11-02-05-53-25.gh-issue-83004.qc_KHr.rst [new file with mode: 0644]
Modules/_pickle.c

diff --git a/Misc/NEWS.d/next/Library/2022-11-02-05-53-25.gh-issue-83004.qc_KHr.rst b/Misc/NEWS.d/next/Library/2022-11-02-05-53-25.gh-issue-83004.qc_KHr.rst
new file mode 100644 (file)
index 0000000..de00063
--- /dev/null
@@ -0,0 +1 @@
+Clean up refleaks on failed module initialisation in in :mod:`_pickle`
index ce54a2dbf3de34cd8418cee02cffe03e9448840a..956c7b6f816b9b2a70fd8662ba546d2d32052a4e 100644 (file)
@@ -8027,16 +8027,15 @@ PyInit__pickle(void)
     if (st->UnpicklingError == NULL)
         return NULL;
 
-    Py_INCREF(st->PickleError);
-    if (PyModule_AddObject(m, "PickleError", st->PickleError) < 0)
+    if (PyModule_AddObjectRef(m, "PickleError", st->PickleError) < 0) {
         return NULL;
-    Py_INCREF(st->PicklingError);
-    if (PyModule_AddObject(m, "PicklingError", st->PicklingError) < 0)
+    }
+    if (PyModule_AddObjectRef(m, "PicklingError", st->PicklingError) < 0) {
         return NULL;
-    Py_INCREF(st->UnpicklingError);
-    if (PyModule_AddObject(m, "UnpicklingError", st->UnpicklingError) < 0)
+    }
+    if (PyModule_AddObjectRef(m, "UnpicklingError", st->UnpicklingError) < 0) {
         return NULL;
-
+    }
     if (_Pickle_InitState(st) < 0)
         return NULL;