bpo-40645: Fix ref leaks in _hashopenssl (GH-26079)

This commit is contained in:
Erlend Egeberg Aasland 2021-05-12 20:20:41 +02:00 committed by GitHub
parent e5ba1fe995
commit 504ffdae4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -2093,23 +2093,27 @@ hashlib_init_constructors(PyObject *module)
}
func = PyObject_GetAttrString(module, fdef->ml_name);
if (func == NULL) {
Py_DECREF(name_obj);
return -1;
}
if (PyDict_SetItem(state->constructs, func, name_obj) < 0) {
return -1;
}
int rc = PyDict_SetItem(state->constructs, func, name_obj);
Py_DECREF(func);
Py_DECREF(name_obj);
if (rc < 0) {
return -1;
}
}
proxy = PyDictProxy_New(state->constructs);
if (proxy == NULL) {
return -1;
}
if (PyModule_AddObjectRef(module, "_constructors", proxy) < 0) {
int rc = PyModule_AddObjectRef(module, "_constructors", proxy);
Py_DECREF(proxy);
if (rc < 0) {
return -1;
}
Py_DECREF(proxy);
return 0;
}