]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[2.7] bpo-36179: Fix ref leaks in _hashopenssl (GH-12158) (GH-12166)
authorChristian Heimes <christian@python.org>
Mon, 4 Mar 2019 17:10:45 +0000 (18:10 +0100)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 4 Mar 2019 17:10:45 +0000 (09:10 -0800)
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@python.org>
https://bugs.python.org/issue36179.
(cherry picked from commit b7bc283ab6a23ee98784400ebffe7fe410232a2e)

Co-authored-by: Christian Heimes <christian@python.org>
https://bugs.python.org/issue36179

Misc/NEWS.d/next/Library/2019-03-04-10-42-46.bpo-36179.jEyuI-.rst [new file with mode: 0644]
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 (file)
index 0000000..61a9877
--- /dev/null
@@ -0,0 +1,2 @@
+Fix two unlikely reference leaks in _hashopenssl. The leaks only occur in
+out-of-memory cases.
index de69f6fcd037669e3c96fbd3b89e5ce03a82c08f..78445ebabdd33c26072af9341b2326ed17688159 100644 (file)
@@ -133,12 +133,6 @@ newEVPobject(PyObject *name)
     if (retval == NULL)
         return NULL;
 
-    retval->ctx = EVP_MD_CTX_new();
-    if (retval->ctx == NULL) {
-        PyErr_NoMemory();
-        return NULL;
-    }
-
     /* save the name for .name to return */
     Py_INCREF(name);
     retval->name = name;
@@ -146,6 +140,13 @@ newEVPobject(PyObject *name)
     retval->lock = NULL;
 #endif
 
+    retval->ctx = EVP_MD_CTX_new();
+    if (retval->ctx == NULL) {
+        Py_DECREF(retval);
+        PyErr_NoMemory();
+        return NULL;
+    }
+
     return retval;
 }
 
@@ -205,6 +206,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;