diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7f640bce2515..9a14fa2b790b 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1423,11 +1423,15 @@ test_widechar(PyObject *self) if (wide == NULL) return NULL; PyUnicode_AS_UNICODE(wide)[0] = invalid[0]; - if (_PyUnicode_Ready(wide) < 0) + if (_PyUnicode_Ready(wide) < 0) { + Py_DECREF(wide); PyErr_Clear(); - else + } + else { + Py_DECREF(wide); return raiseTestError("test_widechar", "PyUnicode_Ready() didn't fail"); + } #endif Py_RETURN_NONE;