This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/1072: Exception-unsafe code in locale
- To: gcc-gnats at gcc dot gnu dot org
- Subject: libstdc++/1072: Exception-unsafe code in locale
- From: peturr at usa dot net
- Date: 15 Dec 2000 21:47:26 -0000
- Reply-To: peturr at usa dot net
>Number: 1072
>Category: libstdc++
>Synopsis: Exception-unsafe code in locale
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Dec 15 13:56:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Petur Runolfsson
>Release: gcc version 2.97 20001211 (experimental)
>Organization:
>Environment:
i586-pc-linux-gnu
>Description:
This code is from libstdc++-v3/src/localename.cc:
locale::_Impl::
_Impl(const _Impl& __other, const string& __name, category __cat,
size_t __refs)
: _M_references(__refs - 1), _M_has_name(__other._M_name != "*")
{
__cat = _S_normalize_category(__cat); // might throw
try
{ _M_facets = new __vec_facet(*(__other._M_facets)); }
catch(...)
{
delete _M_facets;
throw;
}
try
{ _M_category_names = new __vec_string(*(__other._M_category_names)); }
catch(...)
{
delete _M_category_names;
throw;
}
These catch blocks are useless since the target pointers
are never modified if either operator new or the
constructors throw an exception. In fact, they will
probably cause a crash since the pointers are not
initialized before the try block.
Also, if an exception is thrown from the second try block,
the object allocated in the first one is leaked.
This problem appears in all constructors of locale::_Impl
>How-To-Repeat:
>Fix:
Use auto_ptr to guard resources (or don't use pointers
at all and embed the vectors directly in _Impl).
>Release-Note:
>Audit-Trail:
>Unformatted: