◐ Shell
clean mode source ↗

gh-146355: Fix `main_module` ref leak in `_PyRun_SimpleStringFlagsWithName` by A0su · Pull Request #146356 · python/cpython

I dislike this change. IMO it makes the code harder to follow and more complex. I would prefer just that to fix the leak:

diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index a21f494dc69..1e327848e65 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -567,6 +567,7 @@ _PyRun_SimpleStringFlagsWithName(const char *command, const char* name, PyCompil
         PyObject* the_name = PyUnicode_FromString(name);
         if (!the_name) {
             PyErr_Print();
+            Py_DECREF(main_module);
             return -1;
         }
         res = _PyRun_StringFlagsWithName(command, the_name, Py_file_input, dict, dict, flags, 0);

It's a single line to fix the leak.