Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 716aac0

Browse files
committed
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.)
1 parent 27b7f9f commit 716aac0

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Modules/socketmodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,23 +2377,26 @@ PySocket_getaddrinfo(PyObject *self, PyObject *args)
23772377
if ((all = PyList_New(0)) == NULL)
23782378
goto err;
23792379
for (res = res0; res; res = res->ai_next) {
2380+
PyObject *addr =
2381+
makesockaddr(-1, res->ai_addr, res->ai_addrlen);
2382+
if (addr == NULL)
2383+
goto err;
23802384
single = Py_BuildValue("iiisO", res->ai_family,
23812385
res->ai_socktype, res->ai_protocol,
23822386
res->ai_canonname ? res->ai_canonname : "",
2383-
makesockaddr(-1, res->ai_addr, res->ai_addrlen));
2387+
addr);
2388+
Py_DECREF(addr);
23842389
if (single == NULL)
23852390
goto err;
23862391

23872392
if (PyList_Append(all, single))
23882393
goto err;
23892394
Py_XDECREF(single);
23902395
}
2391-
Py_XDECREF(pobj);
23922396
return all;
23932397
err:
23942398
Py_XDECREF(single);
23952399
Py_XDECREF(all);
2396-
Py_XDECREF(pobj);
23972400
return (PyObject *)NULL;
23982401
}
23992402

0 commit comments

Comments
 (0)