summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-29 10:13:22 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-29 10:13:22 (GMT)
commitafb1cb55793669b70f355540389409cedc731d93 (patch)
tree1c66475605983b324726e24cdae24e15a0c96b38 /Objects/unicodeobject.c
parent1e49dde2d929646f172fc7fa46374e7029d7c4fc (diff)
downloadcpython-afb1cb55793669b70f355540389409cedc731d93.zip
cpython-afb1cb55793669b70f355540389409cedc731d93.tar.gz
cpython-afb1cb55793669b70f355540389409cedc731d93.tar.bz2
Issue #16971: Fix a refleak in the charmap decoder.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c17
1 files 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;