Skip to content

Commit 380b12e

Browse files
gh-83004: Clean up refleak in _pickle initialisation (GH-98841)
(cherry picked from commit d3b82b4) Co-authored-by: Shantanu <[email protected]>
1 parent 70006d6 commit 380b12e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up refleaks on failed module initialisation in in :mod:`_pickle`

Modules/_pickle.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8027,16 +8027,15 @@ PyInit__pickle(void)
80278027
if (st->UnpicklingError == NULL)
80288028
return NULL;
80298029

8030-
Py_INCREF(st->PickleError);
8031-
if (PyModule_AddObject(m, "PickleError", st->PickleError) < 0)
8030+
if (PyModule_AddObjectRef(m, "PickleError", st->PickleError) < 0) {
80328031
return NULL;
8033-
Py_INCREF(st->PicklingError);
8034-
if (PyModule_AddObject(m, "PicklingError", st->PicklingError) < 0)
8032+
}
8033+
if (PyModule_AddObjectRef(m, "PicklingError", st->PicklingError) < 0) {
80358034
return NULL;
8036-
Py_INCREF(st->UnpicklingError);
8037-
if (PyModule_AddObject(m, "UnpicklingError", st->UnpicklingError) < 0)
8035+
}
8036+
if (PyModule_AddObjectRef(m, "UnpicklingError", st->UnpicklingError) < 0) {
80388037
return NULL;
8039-
8038+
}
80408039
if (_Pickle_InitState(st) < 0)
80418040
return NULL;
80428041

0 commit comments

Comments
 (0)