https://github.com/python/cpython/commit/2ab7e1135a2d5ca45b60881ece27729e4fc0ee8b commit: 2ab7e1135a2d5ca45b60881ece27729e4fc0ee8b branch: 3.13 author: Serhiy Storchaka <storch...@gmail.com> committer: serhiy-storchaka <storch...@gmail.com> date: 2025-02-26T12:47:41+02:00 summary:
[3.13] gh-130163: Fix a leak in _pickle.c after backporting (GH-130568) files: M Modules/_pickle.c diff --git a/Modules/_pickle.c b/Modules/_pickle.c index edb2c116585880..1ef380d1cd7933 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1938,9 +1938,11 @@ whichmodule(PyObject *global, PyObject *dotted_path) i = 0; while (PyDict_Next(modules, &i, &module_name, &module)) { if (_checkmodule(module_name, module, global, dotted_path) == 0) { + Py_DECREF(modules); return Py_NewRef(module_name); } if (PyErr_Occurred()) { + Py_DECREF(modules); return NULL; } } @@ -1948,6 +1950,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) else { PyObject *iterator = PyObject_GetIter(modules); if (iterator == NULL) { + Py_DECREF(modules); return NULL; } while ((module_name = PyIter_Next(iterator))) { @@ -1955,22 +1958,26 @@ whichmodule(PyObject *global, PyObject *dotted_path) if (module == NULL) { Py_DECREF(module_name); Py_DECREF(iterator); + Py_DECREF(modules); return NULL; } if (_checkmodule(module_name, module, global, dotted_path) == 0) { Py_DECREF(module); Py_DECREF(iterator); + Py_DECREF(modules); return module_name; } Py_DECREF(module); Py_DECREF(module_name); if (PyErr_Occurred()) { Py_DECREF(iterator); + Py_DECREF(modules); return NULL; } } Py_DECREF(iterator); } + Py_DECREF(modules); /* If no module is found, use __main__. */ return &_Py_ID(__main__); _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com