bpo-31544: Fix a reference leak to 'self' after the previous target e… · python/cpython@c498cd8 (original) (raw)
`@@ -2575,14 +2575,24 @@ xmlparser(PyObject* self_, PyObject* args, PyObject* kw)
`
2575
2575
`return NULL;
`
2576
2576
` }
`
2577
2577
``
``
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
+
2578
2591
`/* setup target handlers */
`
2579
2592
`if (!target) {
`
2580
2593
`target = treebuilder_new();
`
2581
2594
`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);
`
2586
2596
`return NULL;
`
2587
2597
` }
`
2588
2598
` } else
`
`@@ -2591,30 +2601,37 @@ xmlparser(PyObject* self_, PyObject* args, PyObject* kw)
`
2591
2601
``
2592
2602
`self->handle_xml = PyObject_GetAttrString(target, "xml");
`
2593
2603
`if (ignore_attribute_error(self->handle_xml)) {
`
``
2604
`+
Py_DECREF(self);
`
2594
2605
`return NULL;
`
2595
2606
` }
`
2596
2607
`self->handle_start = PyObject_GetAttrString(target, "start");
`
2597
2608
`if (ignore_attribute_error(self->handle_start)) {
`
``
2609
`+
Py_DECREF(self);
`
2598
2610
`return NULL;
`
2599
2611
` }
`
2600
2612
`self->handle_data = PyObject_GetAttrString(target, "data");
`
2601
2613
`if (ignore_attribute_error(self->handle_data)) {
`
``
2614
`+
Py_DECREF(self);
`
2602
2615
`return NULL;
`
2603
2616
` }
`
2604
2617
`self->handle_end = PyObject_GetAttrString(target, "end");
`
2605
2618
`if (ignore_attribute_error(self->handle_end)) {
`
``
2619
`+
Py_DECREF(self);
`
2606
2620
`return NULL;
`
2607
2621
` }
`
2608
2622
`self->handle_comment = PyObject_GetAttrString(target, "comment");
`
2609
2623
`if (ignore_attribute_error(self->handle_comment)) {
`
``
2624
`+
Py_DECREF(self);
`
2610
2625
`return NULL;
`
2611
2626
` }
`
2612
2627
`self->handle_pi = PyObject_GetAttrString(target, "pi");
`
2613
2628
`if (ignore_attribute_error(self->handle_pi)) {
`
``
2629
`+
Py_DECREF(self);
`
2614
2630
`return NULL;
`
2615
2631
` }
`
2616
2632
`self->handle_close = PyObject_GetAttrString(target, "close");
`
2617
2633
`if (ignore_attribute_error(self->handle_close)) {
`
``
2634
`+
Py_DECREF(self);
`
2618
2635
`return NULL;
`
2619
2636
` }
`
2620
2637
``
`@@ -2650,8 +2667,6 @@ xmlparser(PyObject* self_, PyObject* args, PyObject* kw)
`
2650
2667
` );
`
2651
2668
`#endif
`
2652
2669
``
2653
``
`-
ALLOC(sizeof(XMLParserObject), "create expatparser");
`
2654
``
-
2655
2670
`return (PyObject*) self;
`
2656
2671
`}
`
2657
2672
``