Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind memory leak
From: Nevin Liber (nevin_at_[hidden])
Date: 2010-11-12 23:20:54


2010/11/12 bit bit <g_rambot_at_[hidden]>

> problematic example:
>
> class A
> {
> public:
> void func1(){throw bad_alloc();};
>
> void func2()
> {
> try
> {
> int i;
> shared_ptr<void> shutdown(static_cast<void*>(0),
> bind(&A::func1, this));
> }
> catch(...)
> {};
> };
> };
>
> int main()
> {
> A a1;
> a1.func2();
> }
>

This problem has nothing to do with bind (which doesn't allocate memory).

Throwing from a deleter is a no-no (and generally a bad design), since the
only time it gets called is by shared_ptr's destructor. Don't do that.
 This is very likely to be a terminating condition using std::shared_ptr in
C++0x.

> --
>
 Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net