bpo-36179: Fix ref leaks in _hashopenssl (GH-12158) · python/cpython@b7bc283

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;