Title: `pythonrun.c`: main_module ref leak in `_PyRun_SimpleStringFlagsWithName` · Issue #146355 · python/cpython · GitHub
Open Graph Title: `pythonrun.c`: main_module ref leak in `_PyRun_SimpleStringFlagsWithName` · Issue #146355 · python/cpython
X Title: `pythonrun.c`: main_module ref leak in `_PyRun_SimpleStringFlagsWithName` · Issue #146355 · python/cpython
Description: Bug report Bug description: Bug report Bug description: This is a sub-issue for #146102 and original gist details can be found here Existing code: int _PyRun_SimpleStringFlagsWithName(const char *command, const char* name, PyCompilerFlag...
Open Graph Description: Bug report Bug description: Bug report Bug description: This is a sub-issue for #146102 and original gist details can be found here Existing code: int _PyRun_SimpleStringFlagsWithName(const char *c...
X Description: Bug report Bug description: Bug report Bug description: This is a sub-issue for #146102 and original gist details can be found here Existing code: int _PyRun_SimpleStringFlagsWithName(const char *c...
Opengraph URL: https://github.com/python/cpython/issues/146355
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`pythonrun.c`: main_module ref leak in `_PyRun_SimpleStringFlagsWithName`","articleBody":"# Bug report\n\n### Bug description:\n\n# Bug report\n### Bug description:\nThis is a sub-issue for #146102 and original gist details can be found [here](https://gist.github.com/devdanzin/86eda5ca53243ef667773991312c2e74)\n\nExisting code:\n```C\nint\n_PyRun_SimpleStringFlagsWithName(const char *command, const char* name, PyCompilerFlags *flags) {\n PyObject *main_module = PyImport_AddModuleRef(\"__main__\");\n if (main_module == NULL) {\n return -1;\n }\n PyObject *dict = PyModule_GetDict(main_module); // borrowed ref\n\n PyObject *res = NULL;\n if (name == NULL) {\n res = PyRun_StringFlags(command, Py_file_input, dict, dict, flags);\n } else {\n PyObject* the_name = PyUnicode_FromString(name);\n if (!the_name) {\n PyErr_Print();\n return -1;\n }\n res = _PyRun_StringFlagsWithName(command, the_name, Py_file_input, dict, dict, flags, 0);\n Py_DECREF(the_name);\n }\n Py_DECREF(main_module);\n if (res == NULL) {\n PyErr_Print();\n return -1;\n }\n\n Py_DECREF(res);\n return 0;\n}\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-146356\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/A0su","@type":"Person","name":"A0su"},"datePublished":"2026-03-24T02:58:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/146355/cpython/issues/146355"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:84cf7bc1-cb60-1659-937e-807efcd27444 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C70E:15A51:18D9720:234F101:6A50C6FB |
| html-safe-nonce | cffa9f73f991f2c0a3b73bd2f36eb7e6ddb31f5eead1215b5ad5185ccae617ff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzBFOjE1QTUxOjE4RDk3MjA6MjM0RjEwMTo2QTUwQzZGQiIsInZpc2l0b3JfaWQiOiIxMzM3NjcxNTYwNDQyNDYzOTk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fdc80ac0d25f061236f4b7af073fa1b1d8cfb56094f598e4cfd41a3b6fd0974d |
| hovercard-subject-tag | issue:4124907504 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/146355/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3995ac68ef1546a5e7044cec243047ef5d93583fecc3b714a9987b8b06d2edaa/python/cpython/issues/146355 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3995ac68ef1546a5e7044cec243047ef5d93583fecc3b714a9987b8b06d2edaa/python/cpython/issues/146355 |
| og:image:alt | Bug report Bug description: Bug report Bug description: This is a sub-issue for #146102 and original gist details can be found here Existing code: int _PyRun_SimpleStringFlagsWithName(const char *c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | A0su |
| hostname | github.com |
| expected-hostname | github.com |
| None | 72b13e0e8d0319acdd27a145cfe73f4f06c791713d0ac4690e41fb68ad28cac0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 08e79d53fc070870d5b168356afebb1e286a2ffe |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width