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

Miss Islington (bot) webhook-mailer at python.org
Thu Nov 15 04:25:48 EST 2018

commit: b5ea5e57f5dd23e1db695dda8bf3f6142ed9074f
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-11-15T01:25:34-08:00

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

"single" needs to be decrefed if PyList_Append() fails.
(cherry picked from commit 4c596d54aa6a55e9d2a3db78891e656ebbfb63c8)

Co-authored-by: Zackery Spytz <zspytz at gmail.com>

M Modules/socketmodule.c

diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index eeade2ecad64..ddb1c4364b91 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -6269,9 +6269,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