bpo-46881: Fix refleak from GH-31616 (GH-31805)

This commit is contained in:
Jelle Zijlstra 2022-03-11 01:05:08 -08:00 committed by GitHub
parent b6a5d8590c
commit 54ab9ad312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -677,10 +677,12 @@ unicode_result_ready(PyObject *unicode)
if (kind == PyUnicode_1BYTE_KIND) {
const Py_UCS1 *data = PyUnicode_1BYTE_DATA(unicode);
Py_UCS1 ch = data[0];
if (unicode != LATIN1(ch)) {
PyObject *latin1_char = LATIN1(ch);
if (unicode != latin1_char) {
Py_INCREF(latin1_char);
Py_DECREF(unicode);
}
return get_latin1_char(ch);
return latin1_char;
}
}