Skip to content

gh-146245: Fix ref/buffer leaks in socketmodule.c on audit hook failure - #146247

Closed
kimimgo wants to merge 1 commit into
python:mainfrom
kimimgo:fix/socket-audit-leak-146245
Closed

gh-146245: Fix ref/buffer leaks in socketmodule.c on audit hook failure#146247
kimimgo wants to merge 1 commit into
python:mainfrom
kimimgo:fix/socket-audit-leak-146245

Conversation

@kimimgo

@kimimgokimimgo commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

Fixes#146245

Summary

Two leak bugs in socketmodule.c when PySys_Audit raises:

1. getaddrinfo (line 6985)

return NULL skipped cleanup of idna and pstr refs. Changed to
goto err which properly calls Py_XDECREF on both.

2. sock_sendto (line 4811)

return NULL skipped PyBuffer_Release(&pbuf). Added the release
before the return, matching the pattern used in adjacent error paths.

… failure
Fix two leak bugs in socketmodule.c when PySys_Audit raises:
1. getaddrinfo: 'return NULL' replaced with 'goto err' to ensure
idna and pstr refs are properly released via Py_XDECREF.
2. sock_sendto: Added PyBuffer_Release(&pbuf) before 'return NULL'
to release the Py_buffer when audit hook raises.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

socketmodule.c: Reference and buffer leaks via audit hook failures

1 participant

@kimimgo