]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36179: Fix ref leaks in _hashopenssl (GH-12158)
authorChristian Heimes <christian@python.org>
Mon, 4 Mar 2019 15:45:41 +0000 (16:45 +0100)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 4 Mar 2019 15:45:41 +0000 (07:45 -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

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 9091025761b9655a5a136a7f484b888db8bcd0f9..aae558c9930301077ac2b0167026de846e64d577 100644 (file)
@@ -109,17 +109,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;
 }
 
@@ -182,6 +183,7 @@ EVP_copy_impl(EVPobject *self)
         return NULL;
 
     if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
+        Py_DECREF(newobj);
         return _setException(PyExc_ValueError);
     }
     return (PyObject *)newobj;