]> granicus.if.org Git - python/commitdiff
#11335: Fix memory leak when a sort key function throws an exception
authorDaniel Stutzbach <daniel@stutzbachenterprises.com>
Wed, 2 Mar 2011 23:37:50 +0000 (23:37 +0000)
committerDaniel Stutzbach <daniel@stutzbachenterprises.com>
Wed, 2 Mar 2011 23:37:50 +0000 (23:37 +0000)
Misc/NEWS
Objects/listobject.c

index 31d7c4c2a999c31371afa7a400eb9f4416cf141c..da1b75d0274a5edea48a95b8e5c6d13b9becc2ff 100644 (file)
--- 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",
index 9b2d36fb9642872684a8d066be1607c303945096..114749ea7839ab123372cc220f03491c1c0f31d2 100644 (file)
@@ -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;
             }
         }