mirror of
https://github.com/python/cpython.git
synced 2025-09-15 05:06:12 +00:00
fix reference leaks in the translate fast path (closes #21175)
Patch by Josh Rosenberg.
This commit is contained in:
parent
fa7e11f8c4
commit
1365de764e
1 changed files with 8 additions and 14 deletions
|
@ -8551,28 +8551,24 @@ static int
|
||||||
unicode_fast_translate_lookup(PyObject *mapping, Py_UCS1 ch,
|
unicode_fast_translate_lookup(PyObject *mapping, Py_UCS1 ch,
|
||||||
Py_UCS1 *translate)
|
Py_UCS1 *translate)
|
||||||
{
|
{
|
||||||
PyObject *item;
|
PyObject *item = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
item = NULL;
|
|
||||||
if (charmaptranslate_lookup(ch, mapping, &item)) {
|
if (charmaptranslate_lookup(ch, mapping, &item)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item == Py_None) {
|
if (item == Py_None) {
|
||||||
/* deletion: skip fast translate */
|
/* deletion */
|
||||||
translate[ch] = 0xfe;
|
translate[ch] = 0xfe;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
else if (item == NULL) {
|
||||||
if (item == NULL) {
|
|
||||||
/* not found => default to 1:1 mapping */
|
/* not found => default to 1:1 mapping */
|
||||||
translate[ch] = ch;
|
translate[ch] = ch;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
else if (PyLong_Check(item)) {
|
||||||
if (PyLong_Check(item)) {
|
Py_UCS4 replace = (Py_UCS4)PyLong_AS_LONG(item);
|
||||||
long replace = (Py_UCS4)PyLong_AS_LONG(item);
|
|
||||||
/* PyLong_AS_LONG() cannot fail, charmaptranslate_lookup() already
|
/* PyLong_AS_LONG() cannot fail, charmaptranslate_lookup() already
|
||||||
used it */
|
used it */
|
||||||
if (127 < replace) {
|
if (127 < replace) {
|
||||||
|
@ -8598,15 +8594,13 @@ unicode_fast_translate_lookup(PyObject *mapping, Py_UCS1 ch,
|
||||||
translate[ch] = (Py_UCS1)replace;
|
translate[ch] = (Py_UCS1)replace;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* not a long or unicode */
|
/* not None, NULL, long or unicode */
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
Py_DECREF(item);
|
|
||||||
item = NULL;
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
Py_XDECREF(item);
|
Py_DECREF(item);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue