classification
Title: Memory leak after key function failure in sort
Type: resource usage Stage: resolved
Components: Interpreter Core Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: stutzbach Nosy List: benjamin.peterson, georg.brandl, pitrou, python-dev, rhettinger, stutzbach
Priority: release blocker Keywords: 3.2regression, needs review, patch

Created on 2011-02-26 17:02 by stutzbach, last changed 2011-05-04 20:08 by stutzbach. This issue is now closed.

Files
File name Uploaded Description Edit
plug-leak.patch stutzbach, 2011-02-26 17:12
Messages (11)
msg129574 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2011-02-26 17:02
In list.sort, if a key function throws an exception, the memory to store the keys is never freed.  I introduced the bug in r86937.  I'll upload a patch for review shortly.
msg129575 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2011-02-26 17:12
Below is a link to the code where leak occurs and the patch goes:

http://svn.python.org/view/python/branches/py3k/Objects/listobject.c?view=markup&pathrev=88554#l1944
msg129579 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-02-26 17:33
LGTM
msg129925 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-03-02 23:46
Is there a way to test this?
msg129926 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-03-02 23:49
Valgrind perhaps?
If the "keys" container was a list or tuple it would simply take a refleak run of the test suite.
msg129927 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2011-03-02 23:53
I'm not sure.  What infrastructure do we have to leaked memory that was allocated with PyMem_MALLOC?
msg129928 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2011-03-02 23:53
I meant "to *detect* leaked memory", of course. :-)
msg129929 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2011-03-03 00:06
I played around with this a little.  That code path doesn't appear to be exercised during the existing unit tests.  I'll add a test so the leak at least shows up when the tests are run under valgrind.
msg134994 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2011-05-02 17:29
I checked in a fix to 3.3 just before the transition to hg.  I confess that I've been procrastinating on getting hg set up properly, which is why I haven't gotten to checking this in to 3.2.

Georg, if I get this in by Wednesday, will that be soon enough for your schedule for 3.2.1?  (it sounds like it will be)
msg135000 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-05-02 19:12
Sure, Wednesday will be fine.
msg135155 - (view) Author: Roundup Robot (python-dev) Date: 2011-05-04 20:06
New changeset 52fb7dc721ed by Daniel Stutzbach in branch '3.2':
#11335: Fix memory leak after key function failure in sort
http://hg.python.org/cpython/rev/52fb7dc721ed

New changeset 18e43c6acfff by Daniel Stutzbach in branch 'default':
#11335: Merge from 3.2: Fix memory leak after key function failure in sort
http://hg.python.org/cpython/rev/18e43c6acfff
History
Date User Action Args
2011-05-04 20:08:26stutzbachsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2011-05-04 20:06:42python-devsetnosy: + python-dev
messages: + msg135155
2011-05-02 19:12:51georg.brandlsetmessages: + msg135000
2011-05-02 17:29:54stutzbachsetpriority: normal -> release blocker
nosy: + georg.brandl
messages: + msg134994

2011-03-03 00:06:11stutzbachsetnosy: rhettinger, pitrou, benjamin.peterson, stutzbach
messages: + msg129929
2011-03-02 23:53:52stutzbachsetnosy: rhettinger, pitrou, benjamin.peterson, stutzbach
messages: + msg129928
2011-03-02 23:53:13stutzbachsetnosy: rhettinger, pitrou, benjamin.peterson, stutzbach
messages: + msg129927
2011-03-02 23:49:01pitrousetnosy: rhettinger, pitrou, benjamin.peterson, stutzbach
messages: + msg129926
2011-03-02 23:46:47rhettingersetnosy: rhettinger, pitrou, benjamin.peterson, stutzbach
messages: + msg129925
2011-02-26 17:33:53benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg129579
2011-02-26 17:12:55stutzbachsetfiles: + plug-leak.patch

messages: + msg129575
keywords: + patch, needs review, 3.2regression
nosy: rhettinger, pitrou, stutzbach
2011-02-26 17:02:24stutzbachcreate