@@ -564,7 +564,7 @@ element_get_attrib(ElementObject* self)
564564LOCAL (PyObject * )
565565element_get_text (ElementObject * self )
566566{
567- /* return borrowed reference to text attribute */
567+ /* return new reference to text attribute */
568568
569569 PyObject * res = self -> text ;
570570
@@ -579,13 +579,13 @@ element_get_text(ElementObject* self)
579579 }
580580 }
581581
582- return res ;
582+ return Py_NewRef ( res ) ;
583583}
584584
585585LOCAL (PyObject * )
586586element_get_tail (ElementObject * self )
587587{
588- /* return borrowed reference to text attribute */
588+ /* return new reference to tail attribute */
589589
590590 PyObject * res = self -> tail ;
591591
@@ -600,7 +600,7 @@ element_get_tail(ElementObject* self)
600600 }
601601 }
602602
603- return res ;
603+ return Py_NewRef ( res ) ;
604604}
605605
606606static PyObject *
@@ -1350,9 +1350,9 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyTypeObject *cls,
13501350 PyObject * text = element_get_text ((ElementObject * )item );
13511351 Py_DECREF (item );
13521352 if (text == Py_None ) {
1353+ Py_DECREF (text );
13531354 return Py_GetConstant (Py_CONSTANT_EMPTY_STR );
13541355 }
1355- Py_XINCREF (text );
13561356 return text ;
13571357 }
13581358 Py_DECREF (item );
@@ -2056,16 +2056,14 @@ static PyObject*
20562056element_text_getter (PyObject * op , void * closure )
20572057{
20582058 ElementObject * self = _Element_CAST (op );
2059- PyObject * res = element_get_text (self );
2060- return Py_XNewRef (res );
2059+ return element_get_text (self );
20612060}
20622061
20632062static PyObject *
20642063element_tail_getter (PyObject * op , void * closure )
20652064{
20662065 ElementObject * self = _Element_CAST (op );
2067- PyObject * res = element_get_tail (self );
2068- return Py_XNewRef (res );
2066+ return element_get_tail (self );
20692067}
20702068
20712069static PyObject *
@@ -2308,16 +2306,14 @@ elementiter_next(PyObject *op)
23082306 continue ;
23092307
23102308gettext :
2309+ Py_DECREF (elem );
23112310 if (!text ) {
2312- Py_DECREF (elem );
23132311 return NULL ;
23142312 }
23152313 if (text == Py_None ) {
2316- Py_DECREF (elem );
2314+ Py_DECREF (text );
23172315 }
23182316 else {
2319- Py_INCREF (text );
2320- Py_DECREF (elem );
23212317 rc = PyObject_IsTrue (text );
23222318 if (rc > 0 )
23232319 return text ;
0 commit comments