This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [libstdc++ PATCH] Fix leak in _Rb_tree::_M_insert (stl_tree.h)
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Earl Chew <earl_chew at agilent dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: 25 Feb 2005 04:07:51 +0100
- Subject: Re: [libstdc++ PATCH] Fix leak in _Rb_tree::_M_insert (stl_tree.h)
- Organization: Integrable Solutions
- References: <421E8AE2.1050108@agilent.com>
Earl Chew <earl_chew@agilent.com> writes:
| Running the exception test suite from STLPort uncovers a
| leak in _Rb_tree::_M_insert when an exception is thrown from
| a comparator.
|
| Earl
|
| --- stl_tree.h.orig 2004-12-12 08:14:30.000000000 -0800
| +++ stl_tree.h 2005-02-24 16:57:15.000000000 -0800
| @@ -781,9 +781,17 @@
| _Link_type __z = _M_create_node(__v);
| bool __insert_left;
|
| - __insert_left = __x != 0 || __p == _M_end()
| - || _M_impl._M_key_compare(_KeyOfValue()(__v),
| - _S_key(__p));
| + try
| + {
| + __insert_left = __x != 0 || __p == _M_end()
| + || _M_impl._M_key_compare(_KeyOfValue()(__v),
| + _S_key(__p));
| + }
| + catch(...)
| + {
| + destroy_node(__z);
| + __throw_exception_again;
| + }
Would there be a way to systematize these expclicit try-block without
efficiency loss (a la RAII or sentry)?
-- Gaby