[Python-checkins] cpython (2.7): Issue #19687: Fixed memory leak on failed Element slice assignment.

serhiy.storchaka python-checkins at python.org
Sun Nov 22 05:31:44 EST 2015


https://hg.python.org/cpython/rev/c33e4881721f
changeset: 99283:c33e4881721f
branch: 2.7
parent: 99279:fd47601145dd
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Nov 22 12:31:11 2015 +0200
summary:
 Issue #19687: Fixed memory leak on failed Element slice assignment.
files:
 Modules/_elementtree.c | 16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1390,15 +1390,17 @@
 
 if (step != 1 && newlen != slicelen)
 {
+ Py_XDECREF(seq);
 PyErr_Format(PyExc_ValueError,
 #if (PY_VERSION_HEX < 0x02050000)
 "attempt to assign sequence of size %d "
 "to extended slice of size %d",
+ (int)newlen, (int)slicelen
 #else
 "attempt to assign sequence of size %zd "
 "to extended slice of size %zd",
+ newlen, slicelen
 #endif
- newlen, slicelen
 );
 return -1;
 }
@@ -1407,9 +1409,7 @@
 /* Resize before creating the recycle bin, to prevent refleaks. */
 if (newlen > slicelen) {
 if (element_resize(self, newlen - slicelen) < 0) {
- if (seq) {
- Py_DECREF(seq);
- }
+ Py_XDECREF(seq);
 return -1;
 }
 }
@@ -1420,9 +1420,7 @@
 we're done modifying the element */
 recycle = PyList_New(slicelen);
 if (!recycle) {
- if (seq) {
- Py_DECREF(seq);
- }
+ Py_XDECREF(seq);
 return -1;
 }
 for (cur = start, i = 0; i < slicelen;
@@ -1450,9 +1448,7 @@
 
 self->extra->length += newlen - slicelen;
 
- if (seq) {
- Py_DECREF(seq);
- }
+ Py_XDECREF(seq);
 
 /* discard the recycle bin, and everything in it */
 Py_XDECREF(recycle);
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /