From afb1cb55793669b70f355540389409cedc731d93 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 29 Jan 2013 12:13:22 +0200 Subject: Issue #16971: Fix a refleak in the charmap decoder. --- Objects/unicodeobject.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b559cb1..e845913 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -7510,14 +7510,18 @@ Error: Py_DECREF(x); goto onError; } - if (unicode_putchar(&v, &outpos, value) < 0) + if (unicode_putchar(&v, &outpos, value) < 0) { + Py_DECREF(x); goto onError; + } } else if (PyUnicode_Check(x)) { Py_ssize_t targetsize; - if (PyUnicode_READY(x) == -1) + if (PyUnicode_READY(x) == -1) { + Py_DECREF(x); goto onError; + } targetsize = PyUnicode_GET_LENGTH(x); if (targetsize == 1) { @@ -7525,8 +7529,10 @@ Error: Py_UCS4 value = PyUnicode_READ_CHAR(x, 0); if (value == 0xFFFE) goto Undefined; - if (unicode_putchar(&v, &outpos, value) < 0) + if (unicode_putchar(&v, &outpos, value) < 0) { + Py_DECREF(x); goto onError; + } } else if (targetsize > 1) { /* 1-n mapping */ @@ -7543,8 +7549,11 @@ Error: goto onError; } } - if (unicode_widen(&v, outpos, PyUnicode_MAX_CHAR_VALUE(x)) < 0) + if (unicode_widen(&v, outpos, + PyUnicode_MAX_CHAR_VALUE(x)) < 0) { + Py_DECREF(x); goto onError; + } PyUnicode_CopyCharacters(v, outpos, x, 0, targetsize); outpos += targetsize; extrachars -= targetsize; -- cgit v0.12