Skip to content

Commit d3b82b4

Browse files
authored
gh-83004: Clean up refleak in _pickle initialisation (#98841)
1 parent 31f2f65 commit d3b82b4

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
@@ -7986,16 +7986,15 @@ PyInit__pickle(void)
79867986
if (st->UnpicklingError == NULL)
79877987
return NULL;
79887988

7989-
Py_INCREF(st->PickleError);
7990-
if (PyModule_AddObject(m, "PickleError", st->PickleError) < 0)
7989+
if (PyModule_AddObjectRef(m, "PickleError", st->PickleError) < 0) {
79917990
return NULL;
7992-
Py_INCREF(st->PicklingError);
7993-
if (PyModule_AddObject(m, "PicklingError", st->PicklingError) < 0)
7991+
}
7992+
if (PyModule_AddObjectRef(m, "PicklingError", st->PicklingError) < 0) {
79947993
return NULL;
7995-
Py_INCREF(st->UnpicklingError);
7996-
if (PyModule_AddObject(m, "UnpicklingError", st->UnpicklingError) < 0)
7994+
}
7995+
if (PyModule_AddObjectRef(m, "UnpicklingError", st->UnpicklingError) < 0) {
79977996
return NULL;
7998-
7997+
}
79997998
if (_Pickle_InitState(st) < 0)
80007999
return NULL;
80018000

0 commit comments

Comments
 (0)