This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients eric.smith, mark.dickinson, skrah, tim.peters
Date 2010-01-16.23:28:14
SpamBayes Score 1.23362e-06
Marked as misclassified No
Message-id <1263684497.5.0.244284116581.issue7632@psf.upfronthosting.co.za>
In-reply-to
Content
Stefan, thanks for that!  I'm not entirely sure how to make use of it, though.  Is there a way to tell Valgrind that some leaks are expected?

The main problem with leak detection is that dtoa.c deliberately keeps hold of any malloc'ed chunks less than a certain size (which I think is something like 2048 bytes, but I'm not sure).  These chunks are never freed in normal use;  instead, they're added to a bunch of free lists for the next time that strtod or dtoa is called.  The logic isn't too complicated:  it's in the functions Balloc and Bfree in dtoa.c.

So the right thing to do is just to check that for each call to strtod, the total number of calls to Balloc matches the total number of calls to Bfree with non-NULL argument.  And similarly for dtoa, except that in that case one of the Balloc'd blocks gets returned to the caller (it's the caller's responsibility to call free_dtoa to free it when it's no longer needed), so there should be a difference of 1.

And there's one further wrinkle:  dtoa.c maintains a list of powers of 5 of the form 5**2**k, and this list is automatically extended with newly allocated Bigints when necessary:  those Bigints are never freed either, so calls to Balloc from that source should be ignored.  Another way round this is just to ignore any leak from the first call to strtod, and then do a repeat call with the same parameters;  the second call will already have all the powers of 5 it needs.
History
Date User Action Args
2010-01-16 23:28:17mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, eric.smith, skrah
2010-01-16 23:28:17mark.dickinsonsetmessageid: <1263684497.5.0.244284116581.issue7632@psf.upfronthosting.co.za>
2010-01-16 23:28:15mark.dickinsonlinkissue7632 messages
2010-01-16 23:28:14mark.dickinsoncreate