diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-10-16 17:24:07 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-10-16 17:24:07 +0000 |
commit | 1bd8b85956d3fb18ce9efbdd6fabb23212d46637 (patch) | |
tree | 4980f05e99f727db30eb95c041e7c98bb689d201 /libstdc++-v3/config/locale/gnu/monetary_members.cc | |
parent | 12440823ab56be8e6e11a7292fc38a92c4e5ae33 (diff) | |
download | gcc-1bd8b85956d3fb18ce9efbdd6fabb23212d46637.tar.gz |
2003-10-16 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/12540
* config/locale/gnu/monetary_members.cc
(moneypunct<wchar_t, true/false>::_M_initialize_moneypunct):
Don't leak memory if new throws.
* src/locale.cc (locale::locale(const char*)): In order not
to leak memory in case new throws, use a basic_string type
for __res too and avoid strdup.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72553 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/config/locale/gnu/monetary_members.cc')
-rw-r--r-- | libstdc++-v3/config/locale/gnu/monetary_members.cc | 196 |
1 files changed, 111 insertions, 85 deletions
diff --git a/libstdc++-v3/config/locale/gnu/monetary_members.cc b/libstdc++-v3/config/locale/gnu/monetary_members.cc index a22bdfe6f24..0c03feb66fa 100644 --- a/libstdc++-v3/config/locale/gnu/monetary_members.cc +++ b/libstdc++-v3/config/locale/gnu/monetary_members.cc @@ -379,47 +379,60 @@ namespace std const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc); const char* __ccurr = __nl_langinfo_l(__INT_CURR_SYMBOL, __cloc); - mbstate_t __state; - size_t __len = strlen(__cpossign); - if (__len) + wchar_t* __wcs_ps = 0; + wchar_t* __wcs_ns = 0; + const char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc)); + try { - ++__len; - memset(&__state, 0, sizeof(mbstate_t)); - wchar_t* __wcs = new wchar_t[__len]; - mbsrtowcs(__wcs, &__cpossign, __len, &__state); - _M_data->_M_positive_sign = __wcs; + mbstate_t __state; + size_t __len = strlen(__cpossign); + if (__len) + { + ++__len; + memset(&__state, 0, sizeof(mbstate_t)); + __wcs_ps = new wchar_t[__len]; + mbsrtowcs(__wcs_ps, &__cpossign, __len, &__state); + _M_data->_M_positive_sign = __wcs_ps; + } + else + _M_data->_M_positive_sign = L""; + + __len = strlen(__cnegsign); + if (!__nposn) + _M_data->_M_negative_sign = L"()"; + else if (__len) + { + ++__len; + memset(&__state, 0, sizeof(mbstate_t)); + __wcs_ns = new wchar_t[__len]; + mbsrtowcs(__wcs_ns, &__cnegsign, __len, &__state); + _M_data->_M_negative_sign = __wcs_ns; + } + else + _M_data->_M_negative_sign = L""; + + // _Intl == true. + __len = strlen(__ccurr); + if (__len) + { + ++__len; + memset(&__state, 0, sizeof(mbstate_t)); + wchar_t* __wcs = new wchar_t[__len]; + mbsrtowcs(__wcs, &__ccurr, __len, &__state); + _M_data->_M_curr_symbol = __wcs; + } + else + _M_data->_M_curr_symbol = L""; } - else - _M_data->_M_positive_sign = L""; - - char __nposn = *(__nl_langinfo_l(__INT_N_SIGN_POSN, __cloc)); - __len = strlen(__cnegsign); - if (!__nposn) - _M_data->_M_negative_sign = L"()"; - else if (__len) - { - ++__len; - memset(&__state, 0, sizeof(mbstate_t)); - wchar_t* __wcs = new wchar_t[__len]; - mbsrtowcs(__wcs, &__cnegsign, __len, &__state); - _M_data->_M_negative_sign = __wcs; - } - else - _M_data->_M_negative_sign = L""; - - // _Intl == true. - __len = strlen(__ccurr); - if (__len) + catch (...) { - ++__len; - memset(&__state, 0, sizeof(mbstate_t)); - wchar_t* __wcs = new wchar_t[__len]; - mbsrtowcs(__wcs, &__ccurr, __len, &__state); - _M_data->_M_curr_symbol = __wcs; - } - else - _M_data->_M_curr_symbol = L""; - + delete _M_data; + _M_data = 0; + delete __wcs_ps; + delete __wcs_ns; + __throw_exception_again; + } + _M_data->_M_frac_digits = *(__nl_langinfo_l(__INT_FRAC_DIGITS, __cloc)); char __pprecedes = *(__nl_langinfo_l(__INT_P_CS_PRECEDES, __cloc)); @@ -442,18 +455,18 @@ namespace std } template<> - void - moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc, -#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) - const char*) + void + moneypunct<wchar_t, false>::_M_initialize_moneypunct(__c_locale __cloc, +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) + const char*) #else - const char* __name) + const char* __name) #endif - { - if (!_M_data) - _M_data = new __moneypunct_cache<wchar_t>; + { + if (!_M_data) + _M_data = new __moneypunct_cache<wchar_t>; - if (!__cloc) + if (!__cloc) { // "C" locale _M_data->_M_decimal_point = L'.'; @@ -489,47 +502,60 @@ namespace std const char* __cnegsign = __nl_langinfo_l(__NEGATIVE_SIGN, __cloc); const char* __ccurr = __nl_langinfo_l(__CURRENCY_SYMBOL, __cloc); - mbstate_t __state; - size_t __len; - __len = strlen(__cpossign); - if (__len) - { - ++__len; - memset(&__state, 0, sizeof(mbstate_t)); - wchar_t* __wcs = new wchar_t[__len]; - mbsrtowcs(__wcs, &__cpossign, __len, &__state); - _M_data->_M_positive_sign = __wcs; - } - else - _M_data->_M_positive_sign = L""; - - char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc)); - __len = strlen(__cnegsign); - if (!__nposn) - _M_data->_M_negative_sign = L"()"; - else if (__len) - { - ++__len; - memset(&__state, 0, sizeof(mbstate_t)); - wchar_t* __wcs = new wchar_t[__len]; - mbsrtowcs(__wcs, &__cnegsign, __len, &__state); - _M_data->_M_negative_sign = __wcs; + wchar_t* __wcs_ps = 0; + wchar_t* __wcs_ns = 0; + const char __nposn = *(__nl_langinfo_l(__N_SIGN_POSN, __cloc)); + try + { + mbstate_t __state; + size_t __len; + __len = strlen(__cpossign); + if (__len) + { + ++__len; + memset(&__state, 0, sizeof(mbstate_t)); + __wcs_ps = new wchar_t[__len]; + mbsrtowcs(__wcs_ps, &__cpossign, __len, &__state); + _M_data->_M_positive_sign = __wcs_ps; + } + else + _M_data->_M_positive_sign = L""; + + __len = strlen(__cnegsign); + if (!__nposn) + _M_data->_M_negative_sign = L"()"; + else if (__len) + { + ++__len; + memset(&__state, 0, sizeof(mbstate_t)); + __wcs_ns = new wchar_t[__len]; + mbsrtowcs(__wcs_ns, &__cnegsign, __len, &__state); + _M_data->_M_negative_sign = __wcs_ns; + } + else + _M_data->_M_negative_sign = L""; + + // _Intl == true. + __len = strlen(__ccurr); + if (__len) + { + ++__len; + memset(&__state, 0, sizeof(mbstate_t)); + wchar_t* __wcs = new wchar_t[__len]; + mbsrtowcs(__wcs, &__ccurr, __len, &__state); + _M_data->_M_curr_symbol = __wcs; + } + else + _M_data->_M_curr_symbol = L""; } - else - _M_data->_M_negative_sign = L""; - - // _Intl == true. - __len = strlen(__ccurr); - if (__len) + catch (...) { - ++__len; - memset(&__state, 0, sizeof(mbstate_t)); - wchar_t* __wcs = new wchar_t[__len]; - mbsrtowcs(__wcs, &__ccurr, __len, &__state); - _M_data->_M_curr_symbol = __wcs; + delete _M_data; + _M_data = 0; + delete __wcs_ps; + delete __wcs_ns; + __throw_exception_again; } - else - _M_data->_M_curr_symbol = L""; _M_data->_M_frac_digits = *(__nl_langinfo_l(__FRAC_DIGITS, __cloc)); char __pprecedes = *(__nl_langinfo_l(__P_CS_PRECEDES, __cloc)); |