[Python-checkins] cpython: fix reference leaks in the translate fast path (closes #21175)
benjamin.peterson
python-checkins at python.org
Tue Apr 8 02:16:17 CEST 2014
http://hg.python.org/cpython/rev/fa6debebfe8b
changeset: 90169:fa6debebfe8b
user: Benjamin Peterson <benjamin at python.org>
date: Mon Apr 07 20:15:41 2014 -0400
summary:
fix reference leaks in the translate fast path (closes #21175)
Patch by Josh Rosenberg.
files:
Objects/unicodeobject.c | 26 ++++++++++----------------
1 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8551,28 +8551,24 @@
unicode_fast_translate_lookup(PyObject *mapping, Py_UCS1 ch,
Py_UCS1 *translate)
{
- PyObject *item;
+ PyObject *item = NULL;
int ret = 0;
- item = NULL;
if (charmaptranslate_lookup(ch, mapping, &item)) {
return -1;
}
if (item == Py_None) {
- /* deletion: skip fast translate */
+ /* deletion */
translate[ch] = 0xfe;
- return 1;
- }
-
- if (item == NULL) {
+ }
+ else if (item == NULL) {
/* not found => default to 1:1 mapping */
translate[ch] = ch;
return 1;
}
-
- if (PyLong_Check(item)) {
- long replace = (Py_UCS4)PyLong_AS_LONG(item);
+ else if (PyLong_Check(item)) {
+ Py_UCS4 replace = (Py_UCS4)PyLong_AS_LONG(item);
/* PyLong_AS_LONG() cannot fail, charmaptranslate_lookup() already
used it */
if (127 < replace) {
@@ -8598,15 +8594,13 @@
translate[ch] = (Py_UCS1)replace;
}
else {
- /* not a long or unicode */
+ /* not None, NULL, long or unicode */
goto exit;
}
+ ret = 1;
+
+ exit:
Py_DECREF(item);
- item = NULL;
- ret = 1;
-
-exit:
- Py_XDECREF(item);
return ret;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list