From 8eda5f7cd9007b6e60be6458f981b504c1442071 Mon Sep 17 00:00:00 2001 From: Daniel Stutzbach Date: Wed, 2 Mar 2011 23:37:50 +0000 Subject: [PATCH] #11335: Fix memory leak when a sort key function throws an exception --- Misc/NEWS | 3 +++ Objects/listobject.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 31d7c4c2a9..da1b75d027 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Issue #11335: Fixed a memory leak in list.sort when the key function + throws an exception. + - Issue #8923: When a string is encoded to UTF-8 in strict mode, the result is cached into the object. Examples: str.encode(), str.encode('utf-8'), PyUnicode_AsUTF8String() and PyUnicode_AsEncodedString(unicode, "utf-8", diff --git a/Objects/listobject.c b/Objects/listobject.c index 9b2d36fb96..114749ea78 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1957,6 +1957,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; } } -- 2.50.1