incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [PATCH] 23.list.iterators 23.list.cons tests with environment
Date Mon, 07 Aug 2006 19:13:10 GMT
Farid Zaripov wrote:
>  > -----Original Message-----
>  > From: Farid Zaripov [mailto:FaridZ@kyiv.vdiweb.com]
>  > Sent: Monday, August 07, 2006 12:33 PM
>  > To: stdcxx-dev@incubator.apache.org
>  > Subject: [PATCH] 23.list.iterators 23.list.cons tests with environment
>  >
>  >   It seems to be list ctors is not exception safe. The test
>  > 23.list.cons asserts about leaks detected when exception is
>  > thrown during call the ctor.
>  >
>  >   The list ctors calls _RWSTD_LIST_INSERT_RANGE macro which,
>  > if an exception was catched, calls the _C_free_buffers()
>  > before rethrow.
>  > But _C_free_buffers() just frees the memory without calling
>  > dtors of the successfully allocated elements. The list dtor
>  > calls clear() before call of _C_free_buffers().
> 
> [...]
> 
>  >
>  >   I'll write the simple test to situate this.
> 
>   The test file is attached.

List does some internal caching but this certainly looks like a bug.
Could you please open an issue in Jira? (Don't forget to copy the
link to this thread in the archives to the issue so that we can
keep track of this discussion in the issue.)

Thanks
Martin

> 
> Farid.
> 
> 
> ------------------------------------------------------------------------
> 
> #include <list>
> #include <cassert>
> 
> static int throw_inx = -1;
> 
> class ListItem
> {
> public:
>     static int count_;
> 
>     void test ()
>     {
>         if (throw_inx == count_)
>             throw count_;
> 
>         ++count_;
>     }
> 
>     ListItem () { test (); }
> 
>     ListItem (const ListItem&) { test (); }
> 
>     ~ListItem () { --count_; }
> };
> 
> int ListItem::count_ = 0;
> 
> int main(int argc, char* argv[])
> {
>     ListItem items [20];
>     std::list<ListItem> lst (20);
> 
>     bool thrown = false;
>     throw_inx = 10;
> 
>     try {
>         ListItem::count_ = 0;
>         std::list<ListItem> test (20);
>     } catch (...) {
>         thrown = true;
>     }
> 
>     assert (thrown && 0 == ListItem::count_);
> 
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         std::list<ListItem> test (20, items [0]);
>     } catch (...) {
>         thrown = true;
>     }
> 
>     assert (thrown && 0 == ListItem::count_);
> 
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         std::list<ListItem> test (items, items + 20);
>     } catch (...) {
>         thrown = true;
>     }
> 
>     assert (thrown && 0 == ListItem::count_);
> 
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         std::list<ListItem> test (lst.begin (), lst.end ());
>     } catch (...) {
>         thrown = true;
>     }
> 
>     assert (thrown && 0 == ListItem::count_);
> 
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         std::list<ListItem> test (lst);
>     } catch (...) {
>         thrown = true;
>     }
> 
>     assert (thrown && 0 == ListItem::count_);
> 
>     return 0;
> }


Mime
View raw message