René's URL Explorer Experiment


Title: Memory leak in test_sys with subinterpreters creation (AddressSanitizer detection) · Issue #140067 · python/cpython · GitHub

Open Graph Title: Memory leak in test_sys with subinterpreters creation (AddressSanitizer detection) · Issue #140067 · python/cpython

X Title: Memory leak in test_sys with subinterpreters creation (AddressSanitizer detection) · Issue #140067 · python/cpython

Description: Bug report Bug description: Bug Description: I've discovered a memory leak when running test_sys with AddressSanitizer enabled. The leak occurs during subinterpreter creation and the allocated memory is never freed. Environment: CPython ...

Open Graph Description: Bug report Bug description: Bug Description: I've discovered a memory leak when running test_sys with AddressSanitizer enabled. The leak occurs during subinterpreter creation and the allocated memo...

X Description: Bug report Bug description: Bug Description: I've discovered a memory leak when running test_sys with AddressSanitizer enabled. The leak occurs during subinterpreter creation and the allocated ...

Opengraph URL: https://github.com/python/cpython/issues/140067

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak in test_sys with subinterpreters creation (AddressSanitizer detection)","articleBody":"# Bug report\n\n### Bug description:\n\n**Bug Description:**\n\nI've discovered a memory leak when running `test_sys` with AddressSanitizer enabled. The leak occurs during subinterpreter creation and the allocated memory is never freed.\n\n**Environment:**\n- CPython versions affected: **3.14 and 3.15 (main branch)**\n- Operating System: Linux (Ubuntu-based)\n- Build configuration:\n```bash\nCC=clang CXX=clang++ ./configure \\\n    --disable-optimizations \\\n    --with-valgrind \\\n    --with-pydebug \\\n    --enable-pystats \\\n    --with-address-sanitizer\n```\n\n**Steps to Reproduce:**\n\n1. Build CPython with the configuration above (tested on both 3.14 and main branches)\n2. Run: `./python -m test test_sys`\n3. Observe AddressSanitizer output at the end\n\n**Expected Behavior:**\nNo memory leaks should be detected by AddressSanitizer.\n\n**Actual Behavior:**\nAddressSanitizer reports approximately 4.5 MB leaked across 20 allocations. All allocations trace back to `_PyInterpreterState_New` → `alloc_interpreter` → `_PyMem_DebugRawCalloc`.\n\nThe test itself passes successfully, but the leak persists:\n```\n== Tests result: SUCCESS ==\n1 test OK.\n=================================================================\nERROR: LeakSanitizer: detected memory leaks\n```\n\n**Reproduction on Multiple Versions:**\n- **3.14 branch**: 4.5 MB leaked (4517100 bytes in 20 allocations)\n- **3.15 (main)**: 4.5 MB leaked (4516460 bytes in 20 allocations)\n\n**Additional Context:**\n\nThe leak appears to be related to subinterpreter lifecycle management. The stack trace shows memory is allocated through:\n- `interp_create` (Modules/_interpretersmodule.c)\n- `_PyXI_NewInterpreter` (Python/crossinterp.c:3204)\n- `Py_NewInterpreterFromConfig` (Python/pylifecycle.c)\n- `new_interpreter` (Python/pylifecycle.c)\n- `_PyInterpreterState_New` (Python/pystate.c)\n- `alloc_interpreter` (Python/pystate.c)\n\nThis issue appears to be related to #110411, which remains open with the latest report from August 2025 stating \"This is still a problem in 3.13.7 and 3.14.0rc2\". Issue #113055 was closed as resolved in February 2025, but the leak still occurs on current 3.14 and main branches.\n\n\u003cdetails\u003e\n\u003csummary\u003eComplete AddressSanitizer Output (3.15 main branch)\u003c/summary\u003e\n\n```\n➜  main git:(main) sudo ./build/main/python -m test test_sys\nUsing random seed: 1335876681\n0:00:00 load avg: 25.72 Run 1 test sequentially in a single process\n0:00:00 load avg: 25.72 [1/1] test_sys\n0:00:20 load avg: 27.57 [1/1] test_sys passed\n\n== Tests result: SUCCESS ==\n\n1 test OK.\n\nTotal duration: 20.6 sec\nTotal tests: run=92 skipped=6\nTotal test files: run=1/1\nResult: SUCCESS\n\n=================================================================\n==544756==ERROR: LeakSanitizer: detected memory leaks\n\nDirect leak of 4290637 byte(s) in 19 object(s) allocated from:\n    #0 0x5c153a3eef9d in calloc (/home/shamil/oss/cpython/main/build/main/python+0x33bf9d) (BuildId: c97dc91acec24b8d7d7a9344676b1bb0726ae568)\n    #1 0x5c153a777a5e in _PyMem_DebugRawAlloc /home/shamil/oss/cpython/main/build/main/../../Objects/obmalloc.c:2884:24\n    #2 0x5c153a777a5e in _PyMem_DebugRawCalloc /home/shamil/oss/cpython/main/build/main/../../Objects/obmalloc.c:2929:12\n    #3 0x5c153abd8578 in alloc_interpreter /home/shamil/oss/cpython/main/build/main/../../Python/pystate.c:462:17\n    #4 0x5c153abd8578 in _PyInterpreterState_New /home/shamil/oss/cpython/main/build/main/../../Python/pystate.c:660:18\n    #5 0x5c153ab8e818 in new_interpreter /home/shamil/oss/cpython/main/build/main/../../Python/pylifecycle.c:2425:14\n    #6 0x5c153ab8e592 in Py_NewInterpreterFromConfig /home/shamil/oss/cpython/main/build/main/../../Python/pylifecycle.c:2521:12\n    #7 0x5c153aab1b58 in _PyXI_NewInterpreter /home/shamil/oss/cpython/main/build/main/../../Python/crossinterp.c:3204:23\n    #8 0x726f325c23ae in _interpreters_create_impl /home/shamil/oss/cpython/main/build/main/../../Modules/_interpretersmodule.c:880:13\n    #9 0x726f325c23ae in _interpreters_create /home/shamil/oss/cpython/main/build/main/../../Modules/clinic/_interpretersmodule.c.h:91:20\n    #10 0x5c153a5e91c2 in _PyObject_VectorcallTstate /home/shamil/oss/cpython/main/build/main/../../Include/internal/pycore_call.h:169:11\n    #11 0x5c153aa11ff6 in _PyEval_EvalFrameDefault /home/shamil/oss/cpython/main/build/main/../../Python/generated_cases.c.h:3188:35\n    [... rest of stack trace truncated for brevity ...]\n\nDirect leak of 225823 byte(s) in 1 object(s) allocated from:\n    #0 0x5c153a3eef9d in calloc (/home/shamil/oss/cpython/main/build/main/python+0x33bf9d) (BuildId: c97dc91acec24b8d7d7a9344676b1bb0726ae568)\n    #1 0x5c153a777a5e in _PyMem_DebugRawAlloc /home/shamil/oss/cpython/main/build/main/../../Objects/obmalloc.c:2884:24\n    #2 0x5c153a777a5e in _PyMem_DebugRawCalloc /home/shamil/oss/cpython/main/build/main/../../Objects/obmalloc.c:2929:12\n    #3 0x5c153abd8578 in alloc_interpreter /home/shamil/oss/cpython/main/build/main/../../Python/pystate.c:462:17\n    #4 0x5c153abd8578 in _PyInterpreterState_New /home/shamil/oss/cpython/main/build/main/../../Python/pystate.c:660:18\n    [... rest of stack trace truncated for brevity ...]\n\nSUMMARY: AddressSanitizer: 4516460 byte(s) leaked in 20 allocation(s).\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eComplete AddressSanitizer Output (3.14 branch)\u003c/summary\u003e\n\n```\n➜  3.14 git:(3.14) sudo ./python -m test test_sys\nUsing random seed: 641571276\n0:00:00 load avg: 2.97 Run 1 test sequentially in a single process\n0:00:00 load avg: 2.97 [1/1] test_sys\n0:00:06 load avg: 2.66 [1/1] test_sys passed\n\n== Tests result: SUCCESS ==\n\n1 test OK.\n\nTotal duration: 6.7 sec\nTotal tests: run=97 skipped=7\nTotal test files: run=1/1\nResult: SUCCESS\n\n=================================================================\n==570353==ERROR: LeakSanitizer: detected memory leaks\n\nDirect leak of 4291245 byte(s) in 19 object(s) allocated from:\n    #0 0x5ea8303c6f8d in calloc (/home/shamil/oss/cpython/3.14/python+0x325f8d) (BuildId: bd4e3657446f867dffe5f140bfa56307be2c714a)\n    #1 0x5ea83074b5be in _PyMem_DebugRawAlloc /home/shamil/oss/cpython/3.14/Objects/obmalloc.c:2869:24\n    #2 0x5ea83074b5be in _PyMem_DebugRawCalloc /home/shamil/oss/cpython/3.14/Objects/obmalloc.c:2914:12\n    #3 0x5ea830b8f5ec in alloc_interpreter /home/shamil/oss/cpython/3.14/Python/pystate.c:570:17\n    #4 0x5ea830b8f5ec in _PyInterpreterState_New /home/shamil/oss/cpython/3.14/Python/pystate.c:757:18\n    #5 0x5ea830b5a2c8 in new_interpreter /home/shamil/oss/cpython/3.14/Python/pylifecycle.c:2313:14\n    #6 0x5ea830b5a042 in Py_NewInterpreterFromConfig /home/shamil/oss/cpython/3.14/Python/pylifecycle.c:2409:12\n    #7 0x5ea830a7cd78 in _PyXI_NewInterpreter /home/shamil/oss/cpython/3.14/Python/crossinterp.c:3204:23\n    #8 0x7be02a35a2a8 in interp_create /home/shamil/oss/cpython/3.14/./Modules/_interpretersmodule.c:862:13\n    [... rest of stack trace truncated for brevity ...]\n\nDirect leak of 225855 byte(s) in 1 object(s) allocated from:\n    #0 0x5ea8303c6f8d in calloc (/home/shamil/oss/cpython/3.14/python+0x325f8d) (BuildId: bd4e3657446f867dffe5f140bfa56307be2c714a)\n    #1 0x5ea83074b5be in _PyMem_DebugRawAlloc /home/shamil/oss/cpython/3.14/Objects/obmalloc.c:2869:24\n    #2 0x5ea83074b5be in _PyMem_DebugRawCalloc /home/shamil/oss/cpython/3.14/Objects/obmalloc.c:2914:12\n    #3 0x5ea830b8f5ec in alloc_interpreter /home/shamil/oss/cpython/3.14/Python/pystate.c:570:17\n    #4 0x5ea830b8f5ec in _PyInterpreterState_New /home/shamil/oss/cpython/3.14/Python/pystate.c:757:18\n    [... rest of stack trace truncated for brevity ...]\n\nSUMMARY: AddressSanitizer: 4517100 byte(s) leaked in 20 allocation(s).\n```\n\u003c/details\u003e\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-140111\n* gh-140118\n* gh-140140\n* gh-140148\n* gh-140261\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ashm-dev","@type":"Person","name":"ashm-dev"},"datePublished":"2025-10-13T22:37:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":17},"url":"https://github.com/140067/cpython/issues/140067"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:747497a8-8877-a1e0-2f1f-bef6bc8b1bca
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8CA4:275F42:828CD7:B4A9B3:696A8066
html-safe-nonceb9876ffb01e1c2158d070c6f6b9deff7c9981d69bc513373dd081170b0c2f55b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0E0OjI3NUY0Mjo4MjhDRDc6QjRBOUIzOjY5NkE4MDY2IiwidmlzaXRvcl9pZCI6IjE3MDYxNzE5MTYxMDg4NTc0NDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac9a682959b20f965893d0b65dae86486cead45b675926712c347422a93e940490
hovercard-subject-tagissue:3511682633
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/140067/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0f01c3c914ad899605f1712e290d90c38c2ef57adf3eef662d99d9b2c31cd8a2/python/cpython/issues/140067
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0f01c3c914ad899605f1712e290d90c38c2ef57adf3eef662d99d9b2c31cd8a2/python/cpython/issues/140067
og:image:altBug report Bug description: Bug Description: I've discovered a memory leak when running test_sys with AddressSanitizer enabled. The leak occurs during subinterpreter creation and the allocated memo...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameashm-dev
hostnamegithub.com
expected-hostnamegithub.com
None913560fa317c3c5a71e34f9b19253c9f09d02b4b958a86c2a56f4c8541116377
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5998c30593994bf2589055aef7b22d368a499367
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/140067#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F140067
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F140067
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/140067
Reloadhttps://github.com/python/cpython/issues/140067
Reloadhttps://github.com/python/cpython/issues/140067
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/140067
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/140067
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/140067
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/140067
#140111https://github.com/python/cpython/pull/140111
Memory leak in test_sys with subinterpreters creation (AddressSanitizer detection)https://github.com/python/cpython/issues/140067#top
#140111https://github.com/python/cpython/pull/140111
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/ashm-dev
https://github.com/ashm-dev
ashm-devhttps://github.com/ashm-dev
on Oct 13, 2025https://github.com/python/cpython/issues/140067#issue-3511682633
4517100https://github.com/python/cpython/commit/4517100e5cfb4b4391618a12889fbfce72996f4d
#110411https://github.com/python/cpython/issues/110411
#113055https://github.com/python/cpython/issues/113055
gh-140067: Fix memory leak in sub-interpreter creation  #140111https://github.com/python/cpython/pull/140111
[3.14] gh-140067: Fix memory leak in sub-interpreter creation (GH-140111) #140118https://github.com/python/cpython/pull/140118
Revert "gh-140067: Fix memory leak in sub-interpreter creation (#140111)" #140140https://github.com/python/cpython/pull/140140
gh-140067: Fix memory leak in subinterpreter creation #140148https://github.com/python/cpython/pull/140148
gh-140067: Fix memory leak in sub-interpreter creation (#140111)  #140261https://github.com/python/cpython/pull/140261
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-subinterpretershttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-subinterpreters%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Subinterpretershttps://github.com/orgs/python/projects/3
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.