]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-130163: Fix a leak in _pickle.c after backporting (GH-130568)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 26 Feb 2025 10:47:41 +0000 (12:47 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Feb 2025 10:47:41 +0000 (12:47 +0200)
Modules/_pickle.c

index edb2c11658588070cb6a88c2205fe71d6a8fd26a..1ef380d1cd7933a4c91392011049504e72f944a3 100644 (file)
@@ -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__);