Skip to content

Embedded Python creates a large number of memory leaks when trying to load a non-existent module #137005

@GShabanov

Description

@GShabanov

Bug report

Bug description:

baseName -- This module does not exist; it was renamed for testing to .py.tmp
After Finalize(); completes and the application is closed, a large number of leaks are created. This behavior is not observed if the module exists.

Sample code

    PyGILState_STATE state = PyGILState_Ensure();

    //
    // check script
    //
    LogMessage(_T("[*] Finding script %s.py...\n"), baseName);

    PyObject* pModuleName;
#ifdef _UNICODE
    pModuleName = PyUnicode_FromWideChar(baseName, -1);
#else  // _UNICODE
    pModuleName = PyUnicode_FromString(baseName);
#endif // _UNICODE

    if (pModuleName)
    {

        pModule = PyImport_GetModule(pModuleName);


        if (pModule)
        {
            Py_DECREF(pModule);

            pModule = PyImport_ReloadModule(pModuleName);
        }
        else
        {

            pModule = PyImport_Import(pModuleName);
        }


        Py_DECREF(pModuleName);
    }

    if (!pModule)
    {
        LogMessage(_T("[-] failed to find module: %s.py\n"), baseName);
        PyGILState_Release(state);
        return false;
    }

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagetopic-C-APItype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy