Skip to content

Commit 84b5ac9

Browse files
tiranmiss-islington
authored andcommitted
[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 <[email protected]> https://bugs.python.org/issue36179. (cherry picked from commit b7bc283) Co-authored-by: Christian Heimes <[email protected]> https://bugs.python.org/issue36179
1 parent 710dcfd commit 84b5ac9

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix two unlikely reference leaks in _hashopenssl. The leaks only occur in
2+
out-of-memory cases.

Modules/_hashopenssl.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,20 @@ newEVPobject(PyObject *name)
133133
if (retval == NULL)
134134
return NULL;
135135

136-
retval->ctx = EVP_MD_CTX_new();
137-
if (retval->ctx == NULL) {
138-
PyErr_NoMemory();
139-
return NULL;
140-
}
141-
142136
/* save the name for .name to return */
143137
Py_INCREF(name);
144138
retval->name = name;
145139
#ifdef WITH_THREAD
146140
retval->lock = NULL;
147141
#endif
148142

143+
retval->ctx = EVP_MD_CTX_new();
144+
if (retval->ctx == NULL) {
145+
Py_DECREF(retval);
146+
PyErr_NoMemory();
147+
return NULL;
148+
}
149+
149150
return retval;
150151
}
151152

@@ -205,6 +206,7 @@ EVP_copy(EVPobject *self, PyObject *unused)
205206
return NULL;
206207

207208
if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
209+
Py_DECREF(newobj);
208210
return _setException(PyExc_ValueError);
209211
}
210212
return (PyObject *)newobj;

0 commit comments

Comments
 (0)