gh-122704: Fix reference leak in Modules/_pickle.c (GH-122705)

This commit is contained in:
Kirill Podoprigora 2024-08-06 08:57:36 +03:00 committed by GitHub
parent b0c48b8fd8
commit 94a4bd79a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -1962,9 +1962,11 @@ whichmodule(PickleState *st, PyObject *global, PyObject *global_name, PyObject *
PyErr_Format(st->PicklingError, PyErr_Format(st->PicklingError,
"Can't pickle %R: import of module %R failed", "Can't pickle %R: import of module %R failed",
global, module_name); global, module_name);
Py_DECREF(module_name);
return NULL; return NULL;
} }
if (check_dotted_path(module, global_name, dotted_path) < 0) { if (check_dotted_path(module, global_name, dotted_path) < 0) {
Py_DECREF(module_name);
Py_DECREF(module); Py_DECREF(module);
return NULL; return NULL;
} }
@ -1974,6 +1976,7 @@ whichmodule(PickleState *st, PyObject *global, PyObject *global_name, PyObject *
PyErr_Format(st->PicklingError, PyErr_Format(st->PicklingError,
"Can't pickle %R: attribute lookup %S on %S failed", "Can't pickle %R: attribute lookup %S on %S failed",
global, global_name, module_name); global, global_name, module_name);
Py_DECREF(module_name);
return NULL; return NULL;
} }
if (actual != global) { if (actual != global) {
@ -1981,6 +1984,7 @@ whichmodule(PickleState *st, PyObject *global, PyObject *global_name, PyObject *
PyErr_Format(st->PicklingError, PyErr_Format(st->PicklingError,
"Can't pickle %R: it's not the same object as %S.%S", "Can't pickle %R: it's not the same object as %S.%S",
global, module_name, global_name); global, module_name, global_name);
Py_DECREF(module_name);
return NULL; return NULL;
} }
Py_DECREF(actual); Py_DECREF(actual);