Title: socketmodule.c: Reference and buffer leaks via audit hook failures · Issue #146245 · python/cpython · GitHub
Open Graph Title: socketmodule.c: Reference and buffer leaks via audit hook failures · Issue #146245 · python/cpython
X Title: socketmodule.c: Reference and buffer leaks via audit hook failures · Issue #146245 · python/cpython
Description: Bug report Bug description: Summary Two leak bugs in socketmodule.c triggered when PySys_Audit raises: getaddrinfo (line 6983): idna and/or pstr refs leaked when audit hook raises. ~657 objects leaked per 1000 calls. sock_sendto (line 48...
Open Graph Description: Bug report Bug description: Summary Two leak bugs in socketmodule.c triggered when PySys_Audit raises: getaddrinfo (line 6983): idna and/or pstr refs leaked when audit hook raises. ~657 objects lea...
X Description: Bug report Bug description: Summary Two leak bugs in socketmodule.c triggered when PySys_Audit raises: getaddrinfo (line 6983): idna and/or pstr refs leaked when audit hook raises. ~657 objects lea...
Opengraph URL: https://github.com/python/cpython/issues/146245
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"socketmodule.c: Reference and buffer leaks via audit hook failures","articleBody":"# Bug report\n\n### Bug description:\n\n## Summary\n\nTwo leak bugs in `socketmodule.c` triggered when `PySys_Audit` raises:\n\n1. `getaddrinfo` (line 6983): `idna` and/or `pstr` refs leaked when audit hook raises. ~657 objects leaked per 1000 calls.\n2. `sock_sendto` (line 4810): `pbuf` Py_buffer not released when audit hook raises.\n\n## Reproducer (getaddrinfo leak)\n\n```python\nimport socket, sys\n\nsys.addaudithook(lambda *a: (_ for _ in ()).throw(RuntimeError(\"audit\")))\nbefore = sys.gettotalrefcount()\nfor i in range(1000):\n try:\n socket.getaddrinfo(\"localhost\", 80)\n except RuntimeError:\n pass\nafter = sys.gettotalrefcount()\nprint(f\"Leaked {after - before} objects in 1000 calls\")\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-146247\n* gh-146248\n* gh-146274\n* gh-146275\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/aisk","@type":"Person","name":"aisk"},"datePublished":"2026-03-21T08:30:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/146245/cpython/issues/146245"}
| 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:14e13884-869d-deb3-c50d-c77516c9ca8e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B848:381E5:62632A:86ED99:6A507462 |
| html-safe-nonce | 0ae358976201d4e6792ac1730b9a8658a9a56dfde77aab27c22cf9da361dab51 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODQ4OjM4MUU1OjYyNjMyQTo4NkVEOTk6NkE1MDc0NjIiLCJ2aXNpdG9yX2lkIjoiMzM2NDE2ODQxNDk2MDU3OTY4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 76fb229c8c488e8f3cb9433697e6feeea47751c51c30bcd7036b9f352e383f3a |
| hovercard-subject-tag | issue:4111812519 |
| 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/146245/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7148a823cf10e4bfb4329b1fd576e54d34a3fb8d60b7d8095c1ab8eca548c6eb/python/cpython/issues/146245 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7148a823cf10e4bfb4329b1fd576e54d34a3fb8d60b7d8095c1ab8eca548c6eb/python/cpython/issues/146245 |
| og:image:alt | Bug report Bug description: Summary Two leak bugs in socketmodule.c triggered when PySys_Audit raises: getaddrinfo (line 6983): idna and/or pstr refs leaked when audit hook raises. ~657 objects lea... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aisk |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| 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 | 7ac0ad2f2c7e4b9056617355fd9e33e22b0c8df9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width