diff options
| author | Benjamin Peterson <benjamin@python.org> | 2014-04-08 00:15:41 (GMT) |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2014-04-08 00:15:41 (GMT) |
| commit | 1365de764eb260c644f10c16ae84d1b637c2d3c5 (patch) | |
| tree | ad73527343f9e940b9de236f4491f38dce01945c /Objects/unicodeobject.c | |
| parent | fa7e11f8c4ae652cbd533b78ac95c0582e03e7c5 (diff) | |
| download | cpython-1365de764eb260c644f10c16ae84d1b637c2d3c5.zip cpython-1365de764eb260c644f10c16ae84d1b637c2d3c5.tar.gz cpython-1365de764eb260c644f10c16ae84d1b637c2d3c5.tar.bz2 | |
fix reference leaks in the translate fast path (closes #21175)
Patch by Josh Rosenberg.
Diffstat (limited to 'Objects/unicodeobject.c')
| -rw-r--r-- | Objects/unicodeobject.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 11f2011..921d7aa 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8551,28 +8551,24 @@ static int 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 @@ unicode_fast_translate_lookup(PyObject *mapping, Py_UCS1 ch, translate[ch] = (Py_UCS1)replace; } else { - /* not a long or unicode */ + /* not None, NULL, long or unicode */ goto exit; } - Py_DECREF(item); - item = NULL; ret = 1; -exit: - Py_XDECREF(item); + exit: + Py_DECREF(item); return ret; } |
