summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_sort.py6
-rw-r--r--Objects/listobject.c2
2 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_sort.py b/Lib/test/test_sort.py
index a7afe73..55503b5 100644
--- a/Lib/test/test_sort.py
+++ b/Lib/test/test_sort.py
@@ -111,6 +111,12 @@ class TestBase(unittest.TestCase):
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
index 18713ab..73624f0 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1944,6 +1944,8 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
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;
}
}