summaryrefslogtreecommitdiff
path: root/libstdc++-v3/src/locale.cc
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2003-10-16 17:24:07 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2003-10-16 17:24:07 +0000
commitf991b1d853560928299d8dea3885da56ad8048b6 (patch)
tree4980f05e99f727db30eb95c041e7c98bb689d201 /libstdc++-v3/src/locale.cc
parent968e3f935ba908bea6ff1348e033be77f652586d (diff)
downloadgcc-f991b1d853560928299d8dea3885da56ad8048b6.tar.gz
re PR libstdc++/12540 (Memory leak in locale::locale(const char*))
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. From-SVN: r72553
Diffstat (limited to 'libstdc++-v3/src/locale.cc')
-rw-r--r--libstdc++-v3/src/locale.cc15
1 files changed, 7 insertions, 8 deletions
diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc
index baa5a4183d7..12f77e1997e 100644
--- a/libstdc++-v3/src/locale.cc
+++ b/libstdc++-v3/src/locale.cc
@@ -208,20 +208,20 @@ namespace std
}
else
{
- char* __res;
+ string __res;
// LANG may set a default different from "C".
char* __env = std::getenv("LANG");
if (!__env || std::strcmp(__env, "") == 0
|| std::strcmp(__env, "C") == 0
|| std::strcmp(__env, "POSIX") == 0)
- __res = strdup("C");
+ __res = "C";
else
- __res = strdup(__env);
+ __res = __env;
// Scan the categories looking for the first one
// different from LANG.
size_t __i = 0;
- if (std::strcmp(__res, "C") == 0)
+ if (std::strcmp(__res.c_str(), "C") == 0)
for (; __i < _S_categories_size; ++__i)
{
__env = std::getenv(_S_categories[__i]);
@@ -235,7 +235,7 @@ namespace std
{
__env = std::getenv(_S_categories[__i]);
if (__env && std::strcmp(__env, "") != 0
- && std::strcmp(__env, __res) != 0)
+ && std::strcmp(__env, __res.c_str()) != 0)
break;
}
@@ -285,11 +285,10 @@ namespace std
}
// ... otherwise either an additional instance of
// the "C" locale or LANG.
- else if (std::strcmp(__res, "C") == 0)
+ else if (std::strcmp(__res.c_str(), "C") == 0)
(_M_impl = _S_classic)->_M_add_reference();
else
- _M_impl = new _Impl(__res, 1);
- std::free(__res);
+ _M_impl = new _Impl(__res.c_str(), 1);
}
}
}