diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-01-12 13:21:06 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-01-12 13:21:06 (GMT) |
commit | 0f3735b8f0ba46556d4f28e8a2cc83ae7519a1d2 (patch) | |
tree | 243be213d6d405d5df4c3d2f74a66f95edddfa18 /Modules | |
parent | a6ebb2d7fbbd943f4f8f1798894c6d7ca5615f2a (diff) | |
parent | b8f6dc855cc3c29fde1cb410cd0e7e316e9a3a94 (diff) | |
download | cpython-0f3735b8f0ba46556d4f28e8a2cc83ae7519a1d2.zip cpython-0f3735b8f0ba46556d4f28e8a2cc83ae7519a1d2.tar.gz cpython-0f3735b8f0ba46556d4f28e8a2cc83ae7519a1d2.tar.bz2 |
Close #16076: fix refleak in pickling of Element.
Thanks to Ezio Melotti and Daniel Shahaf for the patch.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_elementtree.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 2129fc2..8cc9803 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -859,8 +859,10 @@ element_getstate(ElementObject *self) PICKLED_ATTRIB, self->extra->attrib, PICKLED_TEXT, self->text, PICKLED_TAIL, self->tail); - if (instancedict) + if (instancedict) { + Py_DECREF(children); return instancedict; + } else { for (i = 0; i < PyList_GET_SIZE(children); i++) Py_DECREF(PyList_GET_ITEM(children, i)); @@ -884,25 +886,17 @@ element_setstate_from_attributes(ElementObject *self, PyErr_SetString(PyExc_TypeError, "tag may not be NULL"); return NULL; } - if (!text) { - Py_INCREF(Py_None); - text = Py_None; - } - if (!tail) { - Py_INCREF(Py_None); - tail = Py_None; - } Py_CLEAR(self->tag); self->tag = tag; Py_INCREF(self->tag); Py_CLEAR(self->text); - self->text = text; + self->text = text ? text : Py_None; Py_INCREF(self->text); Py_CLEAR(self->tail); - self->tail = tail; + self->tail = tail ? tail : Py_None; Py_INCREF(self->tail); /* Handle ATTRIB and CHILDREN. */ |