summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2019-03-04 17:10:45 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-03-04 17:10:45 (GMT)
commit84b5ac9ba6fd71ba9d0ef98e2a166a35189b263f (patch)
tree1956a80e4bc31767512eac76df8cb230ffdfb06b /Modules
parent710dcfd2f4bee034894a39026388f9c21ea976f1 (diff)
downloadcpython-84b5ac9ba6fd71ba9d0ef98e2a166a35189b263f.zip
cpython-84b5ac9ba6fd71ba9d0ef98e2a166a35189b263f.tar.gz
cpython-84b5ac9ba6fd71ba9d0ef98e2a166a35189b263f.tar.bz2
[2.7] bpo-36179: Fix ref leaks in _hashopenssl (GH-12158) (GH-12166)
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
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_hashopenssl.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index de69f6f..78445eb 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -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;