Skip to content

Commit 504ffda

Browse files
author
Erlend Egeberg Aasland
authored
bpo-40645: Fix ref leaks in _hashopenssl (GH-26079)
1 parent e5ba1fe commit 504ffda

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Modules/_hashopenssl.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,23 +2093,27 @@ hashlib_init_constructors(PyObject *module)
20932093
}
20942094
func = PyObject_GetAttrString(module, fdef->ml_name);
20952095
if (func == NULL) {
2096+
Py_DECREF(name_obj);
20962097
return -1;
20972098
}
2098-
if (PyDict_SetItem(state->constructs, func, name_obj) < 0) {
2099-
return -1;
2100-
}
2099+
int rc = PyDict_SetItem(state->constructs, func, name_obj);
21012100
Py_DECREF(func);
21022101
Py_DECREF(name_obj);
2102+
if (rc < 0) {
2103+
return -1;
2104+
}
21032105
}
21042106

21052107
proxy = PyDictProxy_New(state->constructs);
21062108
if (proxy == NULL) {
21072109
return -1;
21082110
}
2109-
if (PyModule_AddObjectRef(module, "_constructors", proxy) < 0) {
2111+
2112+
int rc = PyModule_AddObjectRef(module, "_constructors", proxy);
2113+
Py_DECREF(proxy);
2114+
if (rc < 0) {
21102115
return -1;
21112116
}
2112-
Py_DECREF(proxy);
21132117
return 0;
21142118
}
21152119

0 commit comments

Comments
 (0)