@@ -324,19 +324,22 @@ static PyObject*
324324get_attrib_from_keywords (PyObject * kwds )
325325{
326326 PyObject * attrib_str = PyUnicode_FromString ("attrib" );
327- PyObject * attrib = PyDict_GetItem (kwds , attrib_str );
327+ PyObject * attrib = PyDict_GetItemRef (kwds , attrib_str );
328328
329329 if (attrib ) {
330330 /* If attrib was found in kwds, copy its value and remove it from
331331 * kwds
332332 */
333333 if (!PyDict_Check (attrib )) {
334+ Py_DECREF (attrib );
334335 Py_DECREF (attrib_str );
335336 PyErr_Format (PyExc_TypeError , "attrib must be dict, not %T" ,
336337 attrib );
337338 return NULL ;
338339 }
339- attrib = PyDict_Copy (attrib );
340+ PyObject * copy = PyDict_Copy (attrib );
341+ Py_DECREF (attrib );
342+ attrib = copy ;
340343 PyDict_DelItem (kwds , attrib_str );
341344 } else {
342345 attrib = PyDict_New ();
@@ -1341,17 +1344,16 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
13411344 PyObject * default_value )
13421345/*[clinic end generated code: output=523c614142595d75 input=ee153bbf8cdb246e]*/
13431346{
1344- PyObject * value ;
1347+ PyObject * value = NULL ;
13451348
1346- if (!self -> extra || self -> extra -> attrib == Py_None )
1349+ if (self -> extra && self -> extra -> attrib != Py_None )
1350+ value = PyDict_GetItemRef (self -> extra -> attrib , key );
1351+
1352+ if (!value ) {
13471353 value = default_value ;
1348- else {
1349- value = PyDict_GetItem (self -> extra -> attrib , key );
1350- if (!value )
1351- value = default_value ;
1354+ Py_INCREF (value );
13521355 }
13531356
1354- Py_INCREF (value );
13551357 return value ;
13561358}
13571359
@@ -2790,11 +2792,9 @@ makeuniversal(XMLParserObject* self, const char* string)
27902792 if (!key )
27912793 return NULL ;
27922794
2793- value = PyDict_GetItem (self -> names , key );
2795+ value = PyDict_GetItemRef (self -> names , key );
27942796
2795- if (value ) {
2796- Py_INCREF (value );
2797- } else {
2797+ if (!value ) {
27982798 /* new name. convert to universal name, and decode as
27992799 necessary */
28002800
@@ -2916,7 +2916,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
29162916 if (!key )
29172917 return ;
29182918
2919- value = PyDict_GetItem (self -> entity , key );
2919+ value = PyDict_GetItemRef (self -> entity , key );
29202920
29212921 if (value ) {
29222922 if (TreeBuilder_CheckExact (self -> target ))
@@ -2927,6 +2927,7 @@ expat_default_handler(XMLParserObject* self, const XML_Char* data_in,
29272927 res = PyObject_CallFunctionObjArgs (self -> handle_data , value , NULL );
29282928 else
29292929 res = NULL ;
2930+ Py_DECREF (value );
29302931 Py_XDECREF (res );
29312932 } else if (!PyErr_Occurred ()) {
29322933 /* Report the first error, not the last */
0 commit comments