Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-01-17 07:13:33


From: "David Abrahams" <david.abrahams_at_[hidden]>
> struct Base { Base(); ~Base(); };
> struct Derived : Base { Derived(); ~Derived(); };
>
> void unsafe()
> {
> shared_ptr<Derived> d(new Derived);
> shared_ptr<Base> b(d);
> d.reset();
> b.reset(); // equivalent to delete (Base*)(new Derived)!!
> };

It recently occured to me that this is another example that proves release()
extremely dangerous.

A smart shared_ptr can do the right thing on b.reset(), but on b.release()
the user will be left with a Base* and the undefined behavior is not far
away.

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk