bpo-39903: Fix double decref in _elementtree.Element.__getstate__ (GH-18850)
(cherry picked from commit 88944a44aa
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
f3f0c7a108
commit
97bbdb28b4
|
@ -950,8 +950,8 @@ static PyObject *
|
||||||
_elementtree_Element___getstate___impl(ElementObject *self)
|
_elementtree_Element___getstate___impl(ElementObject *self)
|
||||||
/*[clinic end generated code: output=37279aeeb6bb5b04 input=f0d16d7ec2f7adc1]*/
|
/*[clinic end generated code: output=37279aeeb6bb5b04 input=f0d16d7ec2f7adc1]*/
|
||||||
{
|
{
|
||||||
Py_ssize_t i, noattrib;
|
Py_ssize_t i;
|
||||||
PyObject *instancedict = NULL, *children;
|
PyObject *children, *attrib;
|
||||||
|
|
||||||
/* Build a list of children. */
|
/* Build a list of children. */
|
||||||
children = PyList_New(self->extra ? self->extra->length : 0);
|
children = PyList_New(self->extra ? self->extra->length : 0);
|
||||||
|
@ -963,35 +963,26 @@ _elementtree_Element___getstate___impl(ElementObject *self)
|
||||||
PyList_SET_ITEM(children, i, child);
|
PyList_SET_ITEM(children, i, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Construct the state object. */
|
if (self->extra && self->extra->attrib != Py_None) {
|
||||||
noattrib = (self->extra == NULL || self->extra->attrib == Py_None);
|
attrib = self->extra->attrib;
|
||||||
if (noattrib)
|
Py_INCREF(attrib);
|
||||||
instancedict = Py_BuildValue("{sOsOs{}sOsO}",
|
|
||||||
PICKLED_TAG, self->tag,
|
|
||||||
PICKLED_CHILDREN, children,
|
|
||||||
PICKLED_ATTRIB,
|
|
||||||
PICKLED_TEXT, JOIN_OBJ(self->text),
|
|
||||||
PICKLED_TAIL, JOIN_OBJ(self->tail));
|
|
||||||
else
|
|
||||||
instancedict = Py_BuildValue("{sOsOsOsOsO}",
|
|
||||||
PICKLED_TAG, self->tag,
|
|
||||||
PICKLED_CHILDREN, children,
|
|
||||||
PICKLED_ATTRIB, self->extra->attrib,
|
|
||||||
PICKLED_TEXT, JOIN_OBJ(self->text),
|
|
||||||
PICKLED_TAIL, JOIN_OBJ(self->tail));
|
|
||||||
if (instancedict) {
|
|
||||||
Py_DECREF(children);
|
|
||||||
return instancedict;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (i = 0; i < PyList_GET_SIZE(children); i++)
|
attrib = PyDict_New();
|
||||||
Py_DECREF(PyList_GET_ITEM(children, i));
|
if (!attrib) {
|
||||||
Py_DECREF(children);
|
Py_DECREF(children);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Py_BuildValue("{sOsNsNsOsO}",
|
||||||
|
PICKLED_TAG, self->tag,
|
||||||
|
PICKLED_CHILDREN, children,
|
||||||
|
PICKLED_ATTRIB, attrib,
|
||||||
|
PICKLED_TEXT, JOIN_OBJ(self->text),
|
||||||
|
PICKLED_TAIL, JOIN_OBJ(self->tail));
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
element_setstate_from_attributes(ElementObject *self,
|
element_setstate_from_attributes(ElementObject *self,
|
||||||
PyObject *tag,
|
PyObject *tag,
|
||||||
|
|
Loading…
Reference in New Issue