GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `pythonrun.c`: main_module ref leak in `_PyRun_SimpleStringFlagsWithName` · Issue #146355 · python/cpython

pythonrun.c: main_module ref leak in _PyRun_SimpleStringFlagsWithName #146355

New issue
Copy link
New issue
Copy link
Closed
Closed
pythonrun.c: main_module ref leak in _PyRun_SimpleStringFlagsWithName#146355
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@A0su
A0su
opened on Mar 24, 2026
Issue body actions

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, PyCompilerFlags *flags) {
    PyObject *main_module = PyImport_AddModuleRef("__main__");
    if (main_module == NULL) {
        return -1;
    }
    PyObject *dict = PyModule_GetDict(main_module);  // borrowed ref

    PyObject *res = NULL;
    if (name == NULL) {
        res = PyRun_StringFlags(command, Py_file_input, dict, dict, flags);
    } else {
        PyObject* the_name = PyUnicode_FromString(name);
        if (!the_name) {
            PyErr_Print();
            return -1;
        }
        res = _PyRun_StringFlagsWithName(command, the_name, Py_file_input, dict, dict, flags, 0);
        Py_DECREF(the_name);
    }
    Py_DECREF(main_module);
    if (res == NULL) {
        PyErr_Print();
        return -1;
    }

    Py_DECREF(res);
    return 0;
}

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

  • gh-146355: Fix main_module ref leak in _PyRun_SimpleStringFlagsWithName #146356

Activity

  1. A0su
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 24, 2026
  2. sergey-miryanov
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Mar 24, 2026
  3. devdanzin
    added a parent issue on Mar 24, 2026
    • Umbrella issue: bugs found using cpython-review-toolkit #146102
  4. vstinner
    added a commit that references this issue on Mar 25, 2026

    gh-146355: Fix `main_module` ref leak in `_PyRun_SimpleStringFlagsWit…

    08f6b33
  5. vstinner
    closed this as completedon Mar 25, 2026
  6. clin1234
    added a commit that references this issue on Apr 16, 2026

    pythongh-146355: Fix `main_module` ref leak in `_PyRun_SimpleStringFl…

    1660139
  7. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-146355: Fix `main_module` ref leak in `_PyRun_SimpleStringFl…

    5f19328
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.