Skip to content

Commit 6469768

Browse files
miss-islingtonErlend Egeberg Aasland
authored andcommitted
bpo-40645: Fix ref leaks in _hashopenssl (pythonGH-26079)
(cherry picked from commit 504ffda) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
1 parent 7522d3b commit 6469768

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Modules/_hashopenssl.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,20 +2172,25 @@ hashlib_init_constructors(PyObject *module)
21722172
}
21732173
func = PyObject_GetAttrString(module, fdef->ml_name);
21742174
if (func == NULL) {
2175+
Py_DECREF(name_obj);
21752176
return -1;
21762177
}
2177-
if (PyDict_SetItem(state->constructs, func, name_obj) < 0) {
2178-
return -1;
2179-
}
2178+
int rc = PyDict_SetItem(state->constructs, func, name_obj);
21802179
Py_DECREF(func);
21812180
Py_DECREF(name_obj);
2181+
if (rc < 0) {
2182+
return -1;
2183+
}
21822184
}
21832185

21842186
proxy = PyDictProxy_New(state->constructs);
21852187
if (proxy == NULL) {
21862188
return -1;
21872189
}
2188-
if (PyModule_AddObjectRef(module, "_constructors", proxy) < 0) {
2190+
2191+
int rc = PyModule_AddObjectRef(module, "_constructors", proxy);
2192+
Py_DECREF(proxy);
2193+
if (rc < 0) {
21892194
return -1;
21902195
}
21912196
return 0;

0 commit comments

Comments
 (0)