[Python-checkins] cpython (3.2): #11335: Fix memory leak after key function failure in sort

daniel.stutzbach python-checkins at python.org
Wed May 4 22:06:42 CEST 2011


http://hg.python.org/cpython/rev/52fb7dc721ed
changeset: 69836:52fb7dc721ed
branch: 3.2
parent: 69832:2a19d09b08f8
user: Daniel Stutzbach <daniel.stutzbach at google.com>
date: Wed May 04 12:46:28 2011 -0700
summary:
 #11335: Fix memory leak after key function failure in sort
files:
 Lib/test/test_sort.py | 6 ++++++
 Objects/listobject.c | 2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_sort.py b/Lib/test/test_sort.py
--- a/Lib/test/test_sort.py
+++ b/Lib/test/test_sort.py
@@ -111,6 +111,12 @@
 s.sort(key=CmpToKey(lambda a, b: int(random.random() * 3) - 1))
 check("an insane function left some permutation", x, s)
 
+ if len(x) >= 2:
+ def bad_key(x):
+ raise RuntimeError
+ s = x[:]
+ self.assertRaises(RuntimeError, s.sort, key=bad_key)
+
 x = [Complains(i) for i in x]
 s = x[:]
 random.shuffle(s)
diff --git a/Objects/listobject.c b/Objects/listobject.c
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1944,6 +1944,8 @@
 if (keys[i] == NULL) {
 for (i=i-1 ; i>=0 ; i--)
 Py_DECREF(keys[i]);
+ if (keys != &ms.temparray[saved_ob_size+1])
+ PyMem_FREE(keys);
 goto keyfunc_fail;
 }
 }
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

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