Skip to content

Commit cd0f8bf

Browse files
committed
Move decref right after the PyErr_Format
1 parent c8b3427 commit cd0f8bf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Modules/_pickle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,10 +1959,10 @@ whichmodule(PickleState *st, PyObject *global, PyObject *global_name, PyObject *
19591959
extra parameters of __import__ to fix that. */
19601960
module = PyImport_Import(module_name);
19611961
if (module == NULL) {
1962-
Py_DECREF(module_name);
19631962
PyErr_Format(st->PicklingError,
19641963
"Can't pickle %R: import of module %R failed",
19651964
global, module_name);
1965+
Py_DECREF(module_name);
19661966
return NULL;
19671967
}
19681968
if (check_dotted_path(module, global_name, dotted_path) < 0) {
@@ -1973,18 +1973,18 @@ whichmodule(PickleState *st, PyObject *global, PyObject *global_name, PyObject *
19731973
PyObject *actual = getattribute(module, dotted_path);
19741974
Py_DECREF(module);
19751975
if (actual == NULL) {
1976-
Py_DECREF(module_name);
19771976
PyErr_Format(st->PicklingError,
19781977
"Can't pickle %R: attribute lookup %S on %S failed",
19791978
global, global_name, module_name);
1979+
Py_DECREF(module_name);
19801980
return NULL;
19811981
}
19821982
if (actual != global) {
19831983
Py_DECREF(actual);
1984-
Py_DECREF(module_name);
19851984
PyErr_Format(st->PicklingError,
19861985
"Can't pickle %R: it's not the same object as %S.%S",
19871986
global, module_name, global_name);
1987+
Py_DECREF(module_name);
19881988
return NULL;
19891989
}
19901990
Py_DECREF(actual);

0 commit comments

Comments
 (0)