[Python-checkins] bpo-36179: Fix ref leaks in _hashopenssl (GH-12158)

Miss Islington (bot) webhook-mailer at python.org
Mon Mar 4 11:17:34 EST 2019


https://github.com/python/cpython/commit/a59d33a1b08bd3dc9dc2584d4360ca81b0f1ad49
commit: a59d33a1b08bd3dc9dc2584d4360ca81b0f1ad49
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-03-04T08:17:30-08:00
summary:

bpo-36179: Fix ref leaks in _hashopenssl (GH-12158)


Fix two unlikely reference leaks in _hashopenssl. The leaks only occur in
out-of-memory cases. Thanks to Charalampos Stratakis.

Signed-off-by: Christian Heimes <christian at python.org>

https://bugs.python.org/issue36179
(cherry picked from commit b7bc283ab6a23ee98784400ebffe7fe410232a2e)

Co-authored-by: Christian Heimes <christian at python.org>

files:
A Misc/NEWS.d/next/Library/2019-03-04-10-42-46.bpo-36179.jEyuI-.rst
M Modules/_hashopenssl.c

diff --git a/Misc/NEWS.d/next/Library/2019-03-04-10-42-46.bpo-36179.jEyuI-.rst b/Misc/NEWS.d/next/Library/2019-03-04-10-42-46.bpo-36179.jEyuI-.rst
new file mode 100644
index 000000000000..61a98778b78e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-03-04-10-42-46.bpo-36179.jEyuI-.rst
@@ -0,0 +1,2 @@
+Fix two unlikely reference leaks in _hashopenssl. The leaks only occur in
+out-of-memory cases.
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 31d05409f249..b1f0d397aa7e 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -112,17 +112,18 @@ newEVPobject(PyObject *name)
         return NULL;
     }
 
+    /* save the name for .name to return */
+    Py_INCREF(name);
+    retval->name = name;
+    retval->lock = NULL;
+
     retval->ctx = EVP_MD_CTX_new();
     if (retval->ctx == NULL) {
+        Py_DECREF(retval);
         PyErr_NoMemory();
         return NULL;
     }
 
-    /* save the name for .name to return */
-    Py_INCREF(name);
-    retval->name = name;
-    retval->lock = NULL;
-
     return retval;
 }
 
@@ -181,6 +182,7 @@ EVP_copy(EVPobject *self, PyObject *unused)
         return NULL;
 
     if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
+        Py_DECREF(newobj);
         return _setException(PyExc_ValueError);
     }
     return (PyObject *)newobj;



More information about the Python-checkins mailing list