diff --git a/Misc/NEWS.d/next/Library/2026-03-21-00-00-00.gh-issue-146245.SockAud.rst b/Misc/NEWS.d/next/Library/2026-03-21-00-00-00.gh-issue-146245.SockAud.rst new file mode 100644 index 00000000000000..bb0afdef3c5146 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-21-00-00-00.gh-issue-146245.SockAud.rst @@ -0,0 +1,3 @@ +Fix reference leak of ``idna`` and ``pstr`` in :func:`socket.getaddrinfo` +and buffer leak in :meth:`socket.socket.sendto` when ``PySys_Audit`` +raises an exception. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index d4df40c78e8a4f..8215d51baf30e8 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -4808,6 +4808,7 @@ sock_sendto(PyObject *self, PyObject *args) } if (PySys_Audit("socket.sendto", "OO", s, addro) < 0) { + PyBuffer_Release(&pbuf); return NULL; } @@ -6982,7 +6983,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs) if (PySys_Audit("socket.getaddrinfo", "OOiii", hobj, pobj, family, socktype, protocol) < 0) { - return NULL; + goto err; } memset(&hints, 0, sizeof(hints));