[Python-checkins] Fix a possible reference leak in _socket.getaddrinfo(). (GH-10543)

Serhiy Storchaka webhook-mailer at python.org
Wed Nov 14 17:39:06 EST 2018

commit: 4c596d54aa6a55e9d2a3db78891e656ebbfb63c8
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018-11-15T00:39:01+02:00

Fix a possible reference leak in _socket.getaddrinfo(). (GH-10543)

"single" needs to be decrefed if PyList_Append() fails.

M Modules/socketmodule.c

diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 9149641fce5a..a47f0314605c 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -6370,9 +6370,11 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
         if (single == NULL)
             goto err;
-        if (PyList_Append(all, single))
+        if (PyList_Append(all, single)) {
+            Py_DECREF(single);
             goto err;
-        Py_XDECREF(single);
+        }
+        Py_DECREF(single);
     if (res0)

More information about the Python-checkins mailing list