[patch] Some std::locale improvements

Jonathan Wakely jwakely@redhat.com
Wed Dec 10 00:21:00 GMT 2014


On 30/11/14 20:48 +0000, Jonathan Wakely wrote:
>I think we also need this to make __numpunct_cache and
>__moneypunct_cache exception-safe. If we set _M_allocated=true at the
>start of the _M_cache functions and then an allocation throws we will
>delete[] the memory allocated in _M_cache, but then the cache's
>destructor will see _M_allocated==true and will try to delete[] them
>again:
>
> template<typename _CharT>
>   __numpunct_cache<_CharT>::~__numpunct_cache()
>   {
>     if (_M_allocated)
>       {
>         delete [] _M_grouping;
>         delete [] _M_truename;
>         delete [] _M_falsename;
>       }
>   }
>
>Delaying setting the bool and the pointers themselves until after all
>allocations avoids that.
>
>The _M_cache functions were also calling virtual functions twice when
>once is enough.
>
>Finally, __timepunct::_M_cache() is declared but never defined, so I
>want to remove that.
>
>Tested x86_64-linux and powerpc64-linux.
>
>Does anyone see anything wrong with my reasoning above before I commit
>this?

I've committed this to trunk. I was only able to reproduce the
double-free by hacking the library code to throw in that function, so
I've verified manually that this changes fixes it, but don't have
anything to put in the testsuite.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 5996 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20141210/32d21148/attachment.bin>


More information about the Libstdc++ mailing list