Skip to content

Commit 5707792

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 4b1e45e commit 5707792

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed
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

+6-7
Original file line numberDiff line numberDiff line change
@@ -7998,16 +7998,15 @@ PyInit__pickle(void)
79987998
if (st->UnpicklingError == NULL)
79997999
return NULL;
80008000

8001-
Py_INCREF(st->PickleError);
8002-
if (PyModule_AddObject(m, "PickleError", st->PickleError) < 0)
8001+
if (PyModule_AddObjectRef(m, "PickleError", st->PickleError) < 0) {
80038002
return NULL;
8004-
Py_INCREF(st->PicklingError);
8005-
if (PyModule_AddObject(m, "PicklingError", st->PicklingError) < 0)
8003+
}
8004+
if (PyModule_AddObjectRef(m, "PicklingError", st->PicklingError) < 0) {
80068005
return NULL;
8007-
Py_INCREF(st->UnpicklingError);
8008-
if (PyModule_AddObject(m, "UnpicklingError", st->UnpicklingError) < 0)
8006+
}
8007+
if (PyModule_AddObjectRef(m, "UnpicklingError", st->UnpicklingError) < 0) {
80098008
return NULL;
8010-
8009+
}
80118010
if (_Pickle_InitState(st) < 0)
80128011
return NULL;
80138012

0 commit comments

Comments
 (0)