Skip to content

Commit b7bc283

Browse files
tiranmiss-islington
authored andcommitted
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 <[email protected]> https://bugs.python.org/issue36179
1 parent 800d5cd commit b7bc283

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,18 @@ newEVPobject(PyObject *name)
109109
return NULL;
110110
}
111111

112+
/* save the name for .name to return */
113+
Py_INCREF(name);
114+
retval->name = name;
115+
retval->lock = NULL;
116+
112117
retval->ctx = EVP_MD_CTX_new();
113118
if (retval->ctx == NULL) {
119+
Py_DECREF(retval);
114120
PyErr_NoMemory();
115121
return NULL;
116122
}
117123

118-
/* save the name for .name to return */
119-
Py_INCREF(name);
120-
retval->name = name;
121-
retval->lock = NULL;
122-
123124
return retval;
124125
}
125126

@@ -182,6 +183,7 @@ EVP_copy_impl(EVPobject *self)
182183
return NULL;
183184

184185
if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
186+
Py_DECREF(newobj);
185187
return _setException(PyExc_ValueError);
186188
}
187189
return (PyObject *)newobj;

0 commit comments

Comments
 (0)