Title: Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) (Python/crossinterp.c:1319) · Issue #151842 · python/cpython · GitHub
Open Graph Title: Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) (Python/crossinterp.c:1319) · Issue #151842 · python/cpython
X Title: Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) (Python/crossinterp.c:1319) · Issue #151842 · python/cpython
Description: Crash report Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that allocation can fail and return NULL. Th...
Open Graph Description: Crash report Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that...
X Description: Crash report Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that...
Opengraph URL: https://github.com/python/cpython/issues/151842
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) (Python/crossinterp.c:1319)","articleBody":"# Crash report\n\n## Segfault: NULL `info` deref in `_excinfo_clear_type` via `_PyXI_FreeExcInfo(NULL)`\n\n`_interpreters.capture_exception()` builds a `_PyXI_excinfo` via `_PyXI_NewExcInfo()`. Under memory pressure that allocation can fail and return `NULL`. The cleanup path in `_interpreters_capture_exception_impl` then unconditionally calls `_PyXI_FreeExcInfo(info)` with `info == NULL`. `_PyXI_FreeExcInfo` has no NULL guard, so `_PyXI_excinfo_clear` → `_excinfo_clear_type` dereferences `\u0026NULL-\u003etype` (offset 0) at `Python/crossinterp.c:1319` → SIGSEGV.\n\nThis reproduces on all build configurations (a NULL dereference, not a debug-only assert).\n\n### Reproducer\n\n```python\nimport faulthandler, _interpreters\nfaulthandler.enable()\nfrom _testcapi import set_nomemory, remove_mem_hooks\nfor start in range(0, 40):\n try:\n set_nomemory(start, 0)\n try:\n _interpreters.capture_exception(Exception())\n finally:\n remove_mem_hooks()\n except BaseException:\n pass\n finally:\n try: remove_mem_hooks()\n except Exception: pass\n```\n\n### Backtrace\n\n```\n#0 _excinfo_clear_type Python/crossinterp.c:1319 # info == 0x0 -\u003e offset-0 deref\n#1 _PyXI_excinfo_clear Python/crossinterp.c:1374\n#2 _PyXI_FreeExcInfo Python/crossinterp.c:1712 # called with info == NULL, no guard\n#3 _interpreters_capture_exception_impl Modules/_interpretersmodule.c:1544\n#4 cfunction_vectorcall_FASTCALL_KEYWORDS Objects/methodobject.c:465\n```\n\n### Root cause\n\n`Modules/_interpretersmodule.c`, `_interpreters_capture_exception_impl` (≈L1522-1544):\n\n```c\n_PyXI_excinfo *info = _PyXI_NewExcInfo(exc); /* returns NULL under OOM */\nif (info == NULL) {\n goto finally;\n}\n/* ... */\nfinally:\n _PyXI_FreeExcInfo(info); /* L1544: runs even when info == NULL */\n```\n\n`_PyXI_NewExcInfo` (`crossinterp.c:1683`) does `PyMem_RawCalloc` for its struct and, on any failure, `PyMem_RawFree`s it and returns `NULL` — so `info` here is a clean `NULL`, not a dangling half-built struct.\n\n`_PyXI_FreeExcInfo` (`crossinterp.c:1710`) has no NULL guard:\n\n```c\nvoid\n_PyXI_FreeExcInfo(_PyXI_excinfo *info)\n{\n _PyXI_excinfo_clear(info); /* dereferences info */\n PyMem_RawFree(info);\n}\n```\n\n### Suggested fix\n\nMake `_PyXI_FreeExcInfo` NULL-safe, matching the surrounding `PyMem_RawFree(NULL)` idiom (and `Py_XDECREF`, `free()`, etc.):\n\n```c\nvoid\n_PyXI_FreeExcInfo(_PyXI_excinfo *info)\n{\n if (info == NULL) {\n return;\n }\n _PyXI_excinfo_clear(info);\n PyMem_RawFree(info);\n}\n```\n\nThis is more defensive than guarding only the one call site, since the function is part of the cross-interpreter exception ABI and any future caller would otherwise have the same hazard.\n\n### Notes\n\nPart of #151763 (umbrella tracking 35 OOM-related crash findings); OOM-0031 in that table.\n\n### CPython versions tested on:\n\nCPython main branch (3.16.0a0)\n\n### Operating systems tested on:\n\nLinux, Windows\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-151843\n* gh-152031\n* gh-152032\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/amruthamodela06","@type":"Person","name":"amruthamodela06"},"datePublished":"2026-06-21T12:44:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/151842/cpython/issues/151842"}
| 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:b779830f-ea76-9ee5-49c5-228a1b69eaf2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB7A:20E8B8:F6E262:152FA14:6A53B7FD |
| html-safe-nonce | 4310b2a0fd23aace476190e7a24cfb41223bf08e0b1ab6aa9a73611cd9f17d37 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjdBOjIwRThCODpGNkUyNjI6MTUyRkExNDo2QTUzQjdGRCIsInZpc2l0b3JfaWQiOiI3OTczMjAxOTM0NjAwNjE1OTMzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e4904156729df8a3f9141ef375a138ecf3c74beee7d12e94c81166af171ad967 |
| hovercard-subject-tag | issue:4710515779 |
| 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/151842/issue_layout |
| twitter:image | https://opengraph.githubassets.com/42d3e802c716e29469f44523a430d57be81a072d5a27231a314ae8ba1e10dffa/python/cpython/issues/151842 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/42d3e802c716e29469f44523a430d57be81a072d5a27231a314ae8ba1e10dffa/python/cpython/issues/151842 |
| og:image:alt | Crash report Segfault: NULL info deref in _excinfo_clear_type via _PyXI_FreeExcInfo(NULL) _interpreters.capture_exception() builds a _PyXI_excinfo via _PyXI_NewExcInfo(). Under memory pressure that... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | amruthamodela06 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width