@@ -2575,14 +2575,24 @@ xmlparser(PyObject* self_, PyObject* args, PyObject* kw)
25752575 return NULL ;
25762576 }
25772577
2578+ ALLOC (sizeof (XMLParserObject ), "create expatparser" );
2579+
2580+ /* Init to NULL to keep the error handling below manageable. */
2581+ self -> target =
2582+ self -> handle_xml =
2583+ self -> handle_start =
2584+ self -> handle_data =
2585+ self -> handle_end =
2586+ self -> handle_comment =
2587+ self -> handle_pi =
2588+ self -> handle_close =
2589+ NULL ;
2590+
25782591 /* setup target handlers */
25792592 if (!target ) {
25802593 target = treebuilder_new ();
25812594 if (!target ) {
2582- EXPAT (ParserFree )(self -> parser );
2583- PyObject_Del (self -> names );
2584- PyObject_Del (self -> entity );
2585- PyObject_Del (self );
2595+ Py_DECREF (self );
25862596 return NULL ;
25872597 }
25882598 } else
@@ -2591,30 +2601,37 @@ xmlparser(PyObject* self_, PyObject* args, PyObject* kw)
25912601
25922602 self -> handle_xml = PyObject_GetAttrString (target , "xml" );
25932603 if (ignore_attribute_error (self -> handle_xml )) {
2604+ Py_DECREF (self );
25942605 return NULL ;
25952606 }
25962607 self -> handle_start = PyObject_GetAttrString (target , "start" );
25972608 if (ignore_attribute_error (self -> handle_start )) {
2609+ Py_DECREF (self );
25982610 return NULL ;
25992611 }
26002612 self -> handle_data = PyObject_GetAttrString (target , "data" );
26012613 if (ignore_attribute_error (self -> handle_data )) {
2614+ Py_DECREF (self );
26022615 return NULL ;
26032616 }
26042617 self -> handle_end = PyObject_GetAttrString (target , "end" );
26052618 if (ignore_attribute_error (self -> handle_end )) {
2619+ Py_DECREF (self );
26062620 return NULL ;
26072621 }
26082622 self -> handle_comment = PyObject_GetAttrString (target , "comment" );
26092623 if (ignore_attribute_error (self -> handle_comment )) {
2624+ Py_DECREF (self );
26102625 return NULL ;
26112626 }
26122627 self -> handle_pi = PyObject_GetAttrString (target , "pi" );
26132628 if (ignore_attribute_error (self -> handle_pi )) {
2629+ Py_DECREF (self );
26142630 return NULL ;
26152631 }
26162632 self -> handle_close = PyObject_GetAttrString (target , "close" );
26172633 if (ignore_attribute_error (self -> handle_close )) {
2634+ Py_DECREF (self );
26182635 return NULL ;
26192636 }
26202637
@@ -2650,8 +2667,6 @@ xmlparser(PyObject* self_, PyObject* args, PyObject* kw)
26502667 );
26512668#endif
26522669
2653- ALLOC (sizeof (XMLParserObject ), "create expatparser" );
2654-
26552670 return (PyObject * ) self ;
26562671}
26572672
0 commit comments