Skip to content

Commit 452420f

Browse files
[3.13] pythongh-130163: Fix a leak in _pickle.c after backporting (pythonGH-130568)
(cherry picked from commit 2ab7e11)
1 parent 4cf5fc4 commit 452420f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Modules/_pickle.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,39 +1993,46 @@ whichmodule(PyObject *global, PyObject *dotted_path)
19931993
i = 0;
19941994
while (PyDict_Next(modules, &i, &module_name, &module)) {
19951995
if (_checkmodule(module_name, module, global, dotted_path) == 0) {
1996+
Py_DECREF(modules);
19961997
return Py_NewRef(module_name);
19971998
}
19981999
if (PyErr_Occurred()) {
2000+
Py_DECREF(modules);
19992001
return NULL;
20002002
}
20012003
}
20022004
}
20032005
else {
20042006
PyObject *iterator = PyObject_GetIter(modules);
20052007
if (iterator == NULL) {
2008+
Py_DECREF(modules);
20062009
return NULL;
20072010
}
20082011
while ((module_name = PyIter_Next(iterator))) {
20092012
module = PyObject_GetItem(modules, module_name);
20102013
if (module == NULL) {
20112014
Py_DECREF(module_name);
20122015
Py_DECREF(iterator);
2016+
Py_DECREF(modules);
20132017
return NULL;
20142018
}
20152019
if (_checkmodule(module_name, module, global, dotted_path) == 0) {
20162020
Py_DECREF(module);
20172021
Py_DECREF(iterator);
2022+
Py_DECREF(modules);
20182023
return module_name;
20192024
}
20202025
Py_DECREF(module);
20212026
Py_DECREF(module_name);
20222027
if (PyErr_Occurred()) {
20232028
Py_DECREF(iterator);
2029+
Py_DECREF(modules);
20242030
return NULL;
20252031
}
20262032
}
20272033
Py_DECREF(iterator);
20282034
}
2035+
Py_DECREF(modules);
20292036

20302037
/* If no module is found, use __main__. */
20312038
module_name = &_Py_ID(__main__);

0 commit comments

Comments
 (0)