From 6bfcd897582e3f6d12348d053fbf71d5c2639b8b Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 22 Mar 2026 19:29:34 +0800 Subject: [PATCH] gh-146245: Fix reference and buffer leaks via audit hook in socket module (GH-146248) (cherry picked from commit c30fae4bea9f9ba07833e97eb542754c26610765) Co-authored-by: AN Long --- .../2026-03-21-08-48-25.gh-issue-146245.cqM3_4.rst | 1 + Modules/socketmodule.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-08-48-25.gh-issue-146245.cqM3_4.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-08-48-25.gh-issue-146245.cqM3_4.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-08-48-25.gh-issue-146245.cqM3_4.rst new file mode 100644 index 00000000000000..f52eaa0d6c7277 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-03-21-08-48-25.gh-issue-146245.cqM3_4.rst @@ -0,0 +1 @@ +Fixed reference leaks in :mod:`socket` when audit hooks raise exceptions in :func:`socket.getaddrinfo` and :meth:`!socket.sendto`. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 563a930bbcd7ad..c415c93ccb8c9c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -4795,6 +4795,7 @@ sock_sendto(PyObject *self, PyObject *args) } if (PySys_Audit("socket.sendto", "OO", s, addro) < 0) { + PyBuffer_Release(&pbuf); return NULL; } @@ -6965,7 +6966,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));