summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-11-06 14:41:24 (GMT)
committerGitHub <noreply@github.com>2022-11-06 14:41:24 (GMT)
commit57077928ec93cc6e56d58564fee2176a7ac2ebaf (patch)
treec06a37ee1d6aa10c9693fdeff19fbbf9c31543bb
parent4b1e45e78b3f8bc9be7497311cfa36e762f43226 (diff)
downloadcpython-57077928ec93cc6e56d58564fee2176a7ac2ebaf.zip
cpython-57077928ec93cc6e56d58564fee2176a7ac2ebaf.tar.gz
cpython-57077928ec93cc6e56d58564fee2176a7ac2ebaf.tar.bz2
gh-83004: Clean up refleak in _pickle initialisation (GH-98841)
(cherry picked from commit d3b82b4463c4eb51954c0afd98342f0c5e479baa) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
-rw-r--r--Misc/NEWS.d/next/Library/2022-11-02-05-53-25.gh-issue-83004.qc_KHr.rst1
-rw-r--r--Modules/_pickle.c13
2 files changed, 7 insertions, 7 deletions
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 0000000..de00063
--- /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 b4b1dda..721079c 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -7998,16 +7998,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;