moneypunct and __moneypunct_cache

Václav Zeman vhaisman@gmail.com
Sat Dec 28 18:23:00 GMT 2013


Hi.

I am still working on xlocale support for libstdc++ and I have hit some
odd code related to moneypunct facet and its data cache:

Here is __moneypunct_cache<> dtor:

  template<typename _CharT, bool _Intl>
    __moneypunct_cache<_CharT, _Intl>::~__moneypunct_cache()
    {
      if (_M_allocated)
	{
	  delete [] _M_grouping;
	  delete [] _M_curr_symbol;
	  delete [] _M_positive_sign;
	  delete [] _M_negative_sign;
	}
    }

And here is moneypunct facet dtor:

  template<>
    moneypunct<char, true>::~moneypunct()
    {
      if (_M_data->_M_grouping_size)
	delete [] _M_data->_M_grouping;
      if (_M_data->_M_positive_sign_size)
	delete [] _M_data->_M_positive_sign;
      if (_M_data->_M_negative_sign_size
	  && strcmp(_M_data->_M_negative_sign, "()") != 0)
	delete [] _M_data->_M_negative_sign;
      if (_M_data->_M_curr_symbol_size)
	delete [] _M_data->_M_curr_symbol;
      delete _M_data;
    }

  template<>
    moneypunct<char, false>::~moneypunct()
    {
      if (_M_data->_M_grouping_size)
	delete [] _M_data->_M_grouping;
      if (_M_data->_M_positive_sign_size)
	delete [] _M_data->_M_positive_sign;
      if (_M_data->_M_negative_sign_size
	  && strcmp(_M_data->_M_negative_sign, "()") != 0)
	delete [] _M_data->_M_negative_sign;
      if (_M_data->_M_curr_symbol_size)
	delete [] _M_data->_M_curr_symbol;
      delete _M_data;
    }

As you can see above, both dtors are trying to deallocate the memory
used by the _M_data cache. It seems to me that this code in moneypunct
dtor is broken for the case when __moneypunct_cache::_M_allocated ==
true because it will try to deallocate data strings first and then the
same will be attempted by the __moneypunct_cache dtor.

Am I reading the code right or am I missing something here?

-- 
VZ

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 295 bytes
Desc: OpenPGP digital signature
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20131228/5c878f80/attachment.sig>


More information about the Libstdc++ mailing list