@@ -573,7 +573,7 @@ element_get_attrib(ElementObject* self)
573573LOCAL (PyObject * )
574574element_get_text (ElementObject * self )
575575{
576- /* return borrowed reference to text attribute */
576+ /* return new reference to text attribute */
577577
578578 PyObject * res = self -> text ;
579579
@@ -588,13 +588,13 @@ element_get_text(ElementObject* self)
588588 }
589589 }
590590
591- return res ;
591+ return Py_NewRef ( res ) ;
592592}
593593
594594LOCAL (PyObject * )
595595element_get_tail (ElementObject * self )
596596{
597- /* return borrowed reference to text attribute */
597+ /* return new reference to tail attribute */
598598
599599 PyObject * res = self -> tail ;
600600
@@ -609,7 +609,7 @@ element_get_tail(ElementObject* self)
609609 }
610610 }
611611
612- return res ;
612+ return Py_NewRef ( res ) ;
613613}
614614
615615static PyObject *
@@ -1359,9 +1359,9 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyTypeObject *cls,
13591359 PyObject * text = element_get_text ((ElementObject * )item );
13601360 Py_DECREF (item );
13611361 if (text == Py_None ) {
1362+ Py_DECREF (text );
13621363 return Py_GetConstant (Py_CONSTANT_EMPTY_STR );
13631364 }
1364- Py_XINCREF (text );
13651365 return text ;
13661366 }
13671367 Py_DECREF (item );
@@ -2064,16 +2064,14 @@ static PyObject*
20642064element_text_getter (PyObject * op , void * closure )
20652065{
20662066 ElementObject * self = _Element_CAST (op );
2067- PyObject * res = element_get_text (self );
2068- return Py_XNewRef (res );
2067+ return element_get_text (self );
20692068}
20702069
20712070static PyObject *
20722071element_tail_getter (PyObject * op , void * closure )
20732072{
20742073 ElementObject * self = _Element_CAST (op );
2075- PyObject * res = element_get_tail (self );
2076- return Py_XNewRef (res );
2074+ return element_get_tail (self );
20772075}
20782076
20792077static PyObject *
@@ -2316,16 +2314,14 @@ elementiter_next(PyObject *op)
23162314 continue ;
23172315
23182316gettext :
2317+ Py_DECREF (elem );
23192318 if (!text ) {
2320- Py_DECREF (elem );
23212319 return NULL ;
23222320 }
23232321 if (text == Py_None ) {
2324- Py_DECREF (elem );
2322+ Py_DECREF (text );
23252323 }
23262324 else {
2327- Py_INCREF (text );
2328- Py_DECREF (elem );
23292325 rc = PyObject_IsTrue (text );
23302326 if (rc > 0 )
23312327 return text ;
0 commit comments