]> granicus.if.org Git - python/commitdiff
Issue #16971: Fix a refleak in the charmap decoder.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 29 Jan 2013 10:16:57 +0000 (12:16 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 29 Jan 2013 10:16:57 +0000 (12:16 +0200)
1  2 
Objects/unicodeobject.c

index 6eaccbe08456048c119c848c764814503e70b6f0,e8459138a82aad3b0b6cbd32f21252cb28361aa3..cbd2870c1d73ae421af93f0cecbcad5b043d91ab
@@@ -7382,29 -7510,55 +7382,37 @@@ Error
                      Py_DECREF(x);
                      goto onError;
                  }
 -                if (unicode_putchar(&v, &outpos, value) < 0) {
 +
-                 if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1)
++                if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) {
+                     Py_DECREF(x);
                      goto onError;
+                 }
 +                PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value);
 +                writer.pos++;
              }
              else if (PyUnicode_Check(x)) {
-                 if (PyUnicode_READY(x) == -1)
 -                Py_ssize_t targetsize;
 -
+                 if (PyUnicode_READY(x) == -1) {
+                     Py_DECREF(x);
                      goto onError;
 -                targetsize = PyUnicode_GET_LENGTH(x);
 -
 -                if (targetsize == 1) {
 -                    /* 1-1 mapping */
+                 }
 +                if (PyUnicode_GET_LENGTH(x) == 1) {
                      Py_UCS4 value = PyUnicode_READ_CHAR(x, 0);
                      if (value == 0xFFFE)
                          goto Undefined;
-                     if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1)
 -                    if (unicode_putchar(&v, &outpos, value) < 0) {
++                    if (_PyUnicodeWriter_Prepare(&writer, 1, value) == -1) {
+                         Py_DECREF(x);
                          goto onError;
+                     }
 +                    PyUnicode_WRITE(writer.kind, writer.data, writer.pos, value);
 +                    writer.pos++;
                  }
 -                else if (targetsize > 1) {
 -                    /* 1-n mapping */
 -                    if (targetsize > extrachars) {
 -                        /* resize first */
 -                        Py_ssize_t needed = (targetsize - extrachars) + \
 -                            (targetsize << 2);
 -                        extrachars += needed;
 -                        /* XXX overflow detection missing */
 -                        if (unicode_resize(&v,
 -                                           PyUnicode_GET_LENGTH(v) + needed) < 0)
 -                        {
 -                            Py_DECREF(x);
 -                            goto onError;
 -                        }
 -                    }
 -                    if (unicode_widen(&v, outpos,
 -                                      PyUnicode_MAX_CHAR_VALUE(x)) < 0) {
 +                else {
 +                    writer.overallocate = 1;
-                     if (_PyUnicodeWriter_WriteStr(&writer, x) == -1)
++                    if (_PyUnicodeWriter_WriteStr(&writer, x) == -1) {
+                         Py_DECREF(x);
                          goto onError;
 -                    PyUnicode_CopyCharacters(v, outpos, x, 0, targetsize);
 -                    outpos += targetsize;
 -                    extrachars -= targetsize;
+                     }
                  }
 -                /* 1-0 mapping: skip the character */
              }
              else {
                  /* wrong return value */