mirror of
https://github.com/python/cpython.git
synced 2025-07-16 07:45:20 +00:00
gh-100795: Don't call freeaddrinfo on failure. (#101252)
When getaddrinfo returns an error, the output pointer is in an unknown state Don't call freeaddrinfo on it. See the issue for discussion and details with links to reasoning. _Most_ libc getaddrinfo implementations never modify the output pointer unless they are returning success. Co-authored-by: Sergey G. Brester <github@sebres.de> Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
This commit is contained in:
parent
bd7903967c
commit
b724ac2fe7
2 changed files with 7 additions and 0 deletions
|
@ -1085,6 +1085,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int
|
|||
subsequent call to getaddrinfo() does not destroy the
|
||||
outcome of the first call. */
|
||||
if (error) {
|
||||
res = NULL; // no-op, remind us that it is invalid; gh-100795
|
||||
set_gaierror(error);
|
||||
return -1;
|
||||
}
|
||||
|
@ -1195,6 +1196,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int
|
|||
#endif
|
||||
Py_END_ALLOW_THREADS
|
||||
if (error) {
|
||||
res = NULL; // no-op, remind us that it is invalid; gh-100795
|
||||
set_gaierror(error);
|
||||
return -1;
|
||||
}
|
||||
|
@ -6719,6 +6721,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
|
|||
error = getaddrinfo(hptr, pptr, &hints, &res0);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (error) {
|
||||
res0 = NULL; // gh-100795
|
||||
set_gaierror(error);
|
||||
goto err;
|
||||
}
|
||||
|
@ -6815,6 +6818,7 @@ socket_getnameinfo(PyObject *self, PyObject *args)
|
|||
error = getaddrinfo(hostp, pbuf, &hints, &res);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (error) {
|
||||
res = NULL; // gh-100795
|
||||
set_gaierror(error);
|
||||
goto fail;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue