summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey G. Brester <github@sebres.de>2023-01-22 08:10:00 (GMT)
committerGitHub <noreply@github.com>2023-01-22 08:10:00 (GMT)
commit5f08fe4a2c055880c23c6f9b57ff03005d193bfc (patch)
treedb9f4a5561171fca4e9f39745c25d4de1b3955c2
parent95f5b05a8cad61b296807c14e50896075c4dc1de (diff)
downloadcpython-5f08fe4a2c055880c23c6f9b57ff03005d193bfc.zip
cpython-5f08fe4a2c055880c23c6f9b57ff03005d193bfc.tar.gz
cpython-5f08fe4a2c055880c23c6f9b57ff03005d193bfc.tar.bz2
gh-100795: avoid unexpected `freeaddrinfo` after failed `getaddrinfo` (#101220)
Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
-rw-r--r--Misc/NEWS.d/next/Library/2023-01-21-16-50-22.gh-issue-100795.NPMZf7.rst2
-rw-r--r--Modules/socketmodule.c2
2 files changed, 4 insertions, 0 deletions
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
index 0000000..beec5c9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-01-21-16-50-22.gh-issue-100795.NPMZf7.rst
@@ -0,0 +1,2 @@
+Avoid unexpected ``freeaddrinfo`` when :meth:`socket.socket.getaddrinfo`
+fails. Patch by Sergey G. Brester.
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 4747a23..8659d72 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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;
}