[Python-checkins] gh-83004: Clean up refleak in _pickle initialisation (#98841)

JelleZijlstra webhook-mailer at python.org
Sun Nov 6 09:05:19 EST 2022


https://github.com/python/cpython/commit/d3b82b4463c4eb51954c0afd98342f0c5e479baa
commit: d3b82b4463c4eb51954c0afd98342f0c5e479baa
branch: main
author: Shantanu <12621235+hauntsaninja at users.noreply.github.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-11-06T06:05:13-08:00
summary:

gh-83004: Clean up refleak in _pickle initialisation (#98841)

files:
A Misc/NEWS.d/next/Library/2022-11-02-05-53-25.gh-issue-83004.qc_KHr.rst
M 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
index 000000000000..de0006342063
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-11-02-05-53-25.gh-issue-83004.qc_KHr.rst
@@ -0,0 +1 @@
+Clean up refleaks on failed module initialisation in in :mod:`_pickle`
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 52704b0c59ad..80bb2126de7e 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -7986,16 +7986,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;
 



More information about the Python-checkins mailing list