Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-05-03 17:20:51


"Mark Rodgers" <mark.rodgers_at_[hidden]> wrote in message
news:014c01c1f2ed$a8a76c40$0100a8c0_at_mshome.net...
> From: "David B. Held" <dheld_at_[hidden]>
> > > > Also, take note of the situations in which using a
> > > > custom deleter is dangerous.
> > >>
> > shared_ptr<FILE> f(p, fclose);
> > shared_ptr<FILE> g(0, fflush);
> >
> > g = f;
> >
> > Contrived, but compilable.
>
> And harmless?

In this case, maybe. But take the more serious case of Win32
handles with the wrong deallocator specified. Or maybe this is
a better example to illustrate the problem:

void myfree(void* p)
{
    delete p;
}

shared_ptr<int> create()
{
    shared_ptr<int> f(malloc(sizeof(int)), free);

    return shared_ptr<int>(f, myfree);
}

Guess what happens now?

Dave


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