Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f3735b

Browse files
committed
Close #16076: fix refleak in pickling of Element.
Thanks to Ezio Melotti and Daniel Shahaf for the patch.
2 parents a6ebb2d + b8f6dc8 commit 0f3735b

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

Modules/_elementtree.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,10 @@ element_getstate(ElementObject *self)
859859
PICKLED_ATTRIB, self->extra->attrib,
860860
PICKLED_TEXT, self->text,
861861
PICKLED_TAIL, self->tail);
862-
if (instancedict)
862+
if (instancedict) {
863+
Py_DECREF(children);
863864
return instancedict;
865+
}
864866
else {
865867
for (i = 0; i < PyList_GET_SIZE(children); i++)
866868
Py_DECREF(PyList_GET_ITEM(children, i));
@@ -884,25 +886,17 @@ element_setstate_from_attributes(ElementObject *self,
884886
PyErr_SetString(PyExc_TypeError, "tag may not be NULL");
885887
return NULL;
886888
}
887-
if (!text) {
888-
Py_INCREF(Py_None);
889-
text = Py_None;
890-
}
891-
if (!tail) {
892-
Py_INCREF(Py_None);
893-
tail = Py_None;
894-
}
895889

896890
Py_CLEAR(self->tag);
897891
self->tag = tag;
898892
Py_INCREF(self->tag);
899893

900894
Py_CLEAR(self->text);
901-
self->text = text;
895+
self->text = text ? text : Py_None;
902896
Py_INCREF(self->text);
903897

904898
Py_CLEAR(self->tail);
905-
self->tail = tail;
899+
self->tail = tail ? tail : Py_None;
906900
Py_INCREF(self->tail);
907901

908902
/* Handle ATTRIB and CHILDREN. */

0 commit comments

Comments
 (0)