mirror of
https://github.com/python/cpython.git
synced 2025-11-03 19:34:08 +00:00
PySocket_getaddrinfo(): fix two refcount bugs, both having to do with
a misunderstanding of the refcont behavior of the 'O' format code in PyArg_ParseTuple() and Py_BuildValue(), respectively. - pobj is only a borrowed reference, so should *not* be DECREF'ed at the end. This was the cause of SF bug #470635. - The Py_BuildValue() call would leak the object produced by makesockaddr(). (I found this by eyeballing the code.)
This commit is contained in:
parent
27b7f9f91e
commit
716aac0448
1 changed files with 6 additions and 3 deletions
|
|
@ -2377,10 +2377,15 @@ PySocket_getaddrinfo(PyObject *self, PyObject *args)
|
||||||
if ((all = PyList_New(0)) == NULL)
|
if ((all = PyList_New(0)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
for (res = res0; res; res = res->ai_next) {
|
for (res = res0; res; res = res->ai_next) {
|
||||||
|
PyObject *addr =
|
||||||
|
makesockaddr(-1, res->ai_addr, res->ai_addrlen);
|
||||||
|
if (addr == NULL)
|
||||||
|
goto err;
|
||||||
single = Py_BuildValue("iiisO", res->ai_family,
|
single = Py_BuildValue("iiisO", res->ai_family,
|
||||||
res->ai_socktype, res->ai_protocol,
|
res->ai_socktype, res->ai_protocol,
|
||||||
res->ai_canonname ? res->ai_canonname : "",
|
res->ai_canonname ? res->ai_canonname : "",
|
||||||
makesockaddr(-1, res->ai_addr, res->ai_addrlen));
|
addr);
|
||||||
|
Py_DECREF(addr);
|
||||||
if (single == NULL)
|
if (single == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
|
@ -2388,12 +2393,10 @@ PySocket_getaddrinfo(PyObject *self, PyObject *args)
|
||||||
goto err;
|
goto err;
|
||||||
Py_XDECREF(single);
|
Py_XDECREF(single);
|
||||||
}
|
}
|
||||||
Py_XDECREF(pobj);
|
|
||||||
return all;
|
return all;
|
||||||
err:
|
err:
|
||||||
Py_XDECREF(single);
|
Py_XDECREF(single);
|
||||||
Py_XDECREF(all);
|
Py_XDECREF(all);
|
||||||
Py_XDECREF(pobj);
|
|
||||||
return (PyObject *)NULL;
|
return (PyObject *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue