]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-100795: avoid unexpected `freeaddrinfo` after failed `getaddrinfo` (#101220)
authorSergey G. Brester <github@sebres.de>
Sun, 22 Jan 2023 08:10:00 +0000 (09:10 +0100)
committerGitHub <noreply@github.com>
Sun, 22 Jan 2023 08:10:00 +0000 (13:40 +0530)
Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
Misc/NEWS.d/next/Library/2023-01-21-16-50-22.gh-issue-100795.NPMZf7.rst [new file with mode: 0644]
Modules/socketmodule.c

diff --git a/Misc/NEWS.d/next/Library/2023-01-21-16-50-22.gh-issue-100795.NPMZf7.rst b/Misc/NEWS.d/next/Library/2023-01-21-16-50-22.gh-issue-100795.NPMZf7.rst
new file mode 100644 (file)
index 0000000..beec5c9
--- /dev/null
@@ -0,0 +1,2 @@
+Avoid unexpected ``freeaddrinfo`` when :meth:`socket.socket.getaddrinfo`
+fails. Patch by Sergey G. Brester.
index 4747a23e8317fd8869cf08f20ecfa0c030768736..8659d725f2e3a3b08b8b4c52355516754d6e541c 100644 (file)
@@ -6719,6 +6719,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
     error = getaddrinfo(hptr, pptr, &hints, &res0);
     Py_END_ALLOW_THREADS
     if (error) {
+        res0 = NULL;  /* avoid unexpected free if res0 becomes not NULL */
         set_gaierror(error);
         goto err;
     }
@@ -6815,6 +6816,7 @@ socket_getnameinfo(PyObject *self, PyObject *args)
     error = getaddrinfo(hostp, pbuf, &hints, &res);
     Py_END_ALLOW_THREADS
     if (error) {
+        res = NULL;  /* avoid unexpected free if res becomes not NULL */
         set_gaierror(error);
         goto fail;
     }