Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6a69d8

Browse files
Fixed possible leak in ElementTree.Element.iter().
1 parent 3181feb commit d6a69d8

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

Modules/_elementtree.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,17 @@ static PyObject *
13731373
_elementtree_Element_iter_impl(ElementObject *self, PyObject *tag)
13741374
/*[clinic end generated code: output=3f49f9a862941cc5 input=774d5b12e573aedd]*/
13751375
{
1376+
if (PyUnicode_Check(tag)) {
1377+
if (PyUnicode_READY(tag) < 0)
1378+
return NULL;
1379+
if (PyUnicode_GET_LENGTH(tag) == 1 && PyUnicode_READ_CHAR(tag, 0) == '*')
1380+
tag = Py_None;
1381+
}
1382+
else if (PyBytes_Check(tag)) {
1383+
if (PyBytes_GET_SIZE(tag) == 1 && *PyBytes_AS_STRING(tag) == '*')
1384+
tag = Py_None;
1385+
}
1386+
13761387
return create_elementiter(self, tag, 0);
13771388
}
13781389

@@ -2238,17 +2249,6 @@ create_elementiter(ElementObject *self, PyObject *tag, int gettext)
22382249
if (!it)
22392250
return NULL;
22402251

2241-
if (PyUnicode_Check(tag)) {
2242-
if (PyUnicode_READY(tag) < 0)
2243-
return NULL;
2244-
if (PyUnicode_GET_LENGTH(tag) == 1 && PyUnicode_READ_CHAR(tag, 0) == '*')
2245-
tag = Py_None;
2246-
}
2247-
else if (PyBytes_Check(tag)) {
2248-
if (PyBytes_GET_SIZE(tag) == 1 && *PyBytes_AS_STRING(tag) == '*')
2249-
tag = Py_None;
2250-
}
2251-
22522252
Py_INCREF(tag);
22532253
it->sought_tag = tag;
22542254
it->root_done = 0;

0 commit comments

Comments
 (0)