[Python-checkins] cpython: Issue #15900: Fixed reference leak in PyUnicode_TranslateCharmap()

georg.brandl python-checkins at python.org
Mon Sep 24 07:47:09 CEST 2012


http://hg.python.org/cpython/rev/89f62f143920
changeset:   79120:89f62f143920
user:        Christian Heimes <christian at cheimes.de>
date:        Tue Sep 11 14:03:25 2012 +0200
summary:
  Issue #15900: Fixed reference leak in PyUnicode_TranslateCharmap()

files:
  Misc/NEWS               |   2 ++
  Objects/unicodeobject.c |  11 +++++------
  2 files changed, 7 insertions(+), 6 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- Issue #15900: Fixed reference leak in PyUnicode_TranslateCharmap().
+
 - Issue #15926: Fix crash after multiple reinitializations of the interpreter.
 
 - Issue #15895: Fix FILE pointer leak in one error branch of
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8585,10 +8585,13 @@
                            PyObject *mapping,
                            const char *errors)
 {
+    PyObject *result;
     PyObject *unicode = PyUnicode_FromUnicode(p, size);
     if (!unicode)
         return NULL;
-    return _PyUnicode_TranslateCharmap(unicode, mapping, errors);
+    result = _PyUnicode_TranslateCharmap(unicode, mapping, errors);
+    Py_DECREF(unicode);
+    return result;
 }
 
 PyObject *
@@ -8600,14 +8603,10 @@
 
     str = PyUnicode_FromObject(str);
     if (str == NULL)
-        goto onError;
+        return NULL;
     result = _PyUnicode_TranslateCharmap(str, mapping, errors);
     Py_DECREF(str);
     return result;
-
-  onError:
-    Py_XDECREF(str);
-    return NULL;
 }
 
 static Py_UCS4

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list