[Python-checkins] cpython (merge 3.5 -> default): Fixed possible leak in ElementTree.Element.iter().

serhiy.storchaka python-checkins at python.org
Wed Dec 9 04:28:08 EST 2015


https://hg.python.org/cpython/rev/bb8b75c6bfdf
changeset:   99515:bb8b75c6bfdf
parent:      99513:e587858aa63d
parent:      99514:6633f29771db
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Dec 09 11:27:34 2015 +0200
summary:
  Fixed possible leak in ElementTree.Element.iter().

files:
  Modules/_elementtree.c |  22 +++++++++++-----------
  1 files changed, 11 insertions(+), 11 deletions(-)


diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1373,6 +1373,17 @@
 _elementtree_Element_iter_impl(ElementObject *self, PyObject *tag)
 /*[clinic end generated code: output=3f49f9a862941cc5 input=774d5b12e573aedd]*/
 {
+    if (PyUnicode_Check(tag)) {
+        if (PyUnicode_READY(tag) < 0)
+            return NULL;
+        if (PyUnicode_GET_LENGTH(tag) == 1 && PyUnicode_READ_CHAR(tag, 0) == '*')
+            tag = Py_None;
+    }
+    else if (PyBytes_Check(tag)) {
+        if (PyBytes_GET_SIZE(tag) == 1 && *PyBytes_AS_STRING(tag) == '*')
+            tag = Py_None;
+    }
+
     return create_elementiter(self, tag, 0);
 }
 
@@ -2236,17 +2247,6 @@
     if (!it)
         return NULL;
 
-    if (PyUnicode_Check(tag)) {
-        if (PyUnicode_READY(tag) < 0)
-            return NULL;
-        if (PyUnicode_GET_LENGTH(tag) == 1 && PyUnicode_READ_CHAR(tag, 0) == '*')
-            tag = Py_None;
-    }
-    else if (PyBytes_Check(tag)) {
-        if (PyBytes_GET_SIZE(tag) == 1 && *PyBytes_AS_STRING(tag) == '*')
-            tag = Py_None;
-    }
-
     Py_INCREF(tag);
     it->sought_tag = tag;
     it->root_done = 0;

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


More information about the Python-checkins mailing list