]> granicus.if.org Git - python/commitdiff
Issue #15900: Fixed reference leak in PyUnicode_TranslateCharmap()
authorChristian Heimes <christian@cheimes.de>
Tue, 11 Sep 2012 12:03:25 +0000 (14:03 +0200)
committerChristian Heimes <christian@cheimes.de>
Tue, 11 Sep 2012 12:03:25 +0000 (14:03 +0200)
Misc/NEWS
Objects/unicodeobject.c

index f82da60112bd06774bf57e8ffda205dfa925c4d9..bd44af5fd186bff2a3f39c2141657f38505b5466 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.3.0 Release Candidate 3?
 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
index 773a9be5cc34e81a698bd9b48ad04fdedd08febf..6d49806487fe3dff8eb366ceeb108f9ade303742 100644 (file)
@@ -8585,10 +8585,13 @@ PyUnicode_TranslateCharmap(const Py_UNICODE *p,
                            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 @@ PyUnicode_Translate(PyObject *str,
 
     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