gh-146355: Fix main_module ref leak in _PyRun_SimpleStringFlagsWithName#146356
gh-146355: Fix main_module ref leak in _PyRun_SimpleStringFlagsWithName#146356A0su wants to merge 2 commits intopython:mainfrom
main_module ref leak in _PyRun_SimpleStringFlagsWithName#146356Conversation
…PyRun_SimpleFileObject
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
vstinner
left a comment
There was a problem hiding this comment.
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.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
gh-146355: Fix
main_moduleref leak in_PyRun_SimpleStringFlagsWithNameThis is a sub-issue for #146102 and original gist details can be found here
When
the_nameis NULL we'll fail to callPy_DECREFonmain_module. I used the same goto pattern as_PyRun_SimpleFileObjectto fix this.I omitted a new test entry as we have indirect coverage of functionality in
test_embed.py. Not sure if it makes sense for the scope of fixing the ref leak to include the additional code for a test in test_run.py (which has a TODO for this function).