Boost logo

Boost :

Subject: Re: [boost] possible bug introduced in boost function
From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-09-05 22:06:38

On Fri, Sep 5, 2008 at 6:22 PM, Emil Dotchevski <emil_at_[hidden]> wrote:
> I have strong suspicions that the changes in boost::function made
> today introduce a serious bug in the lifetime management of the
> contained object. I don't have a simple test case to demonstrate it,
> but a rather complicated use of boost::function which contains
> shared_ptr in a boost::bind results in incorrect refcount which leads
> to a crash.
> Reverting to revision 48607 makes the shared_ptr refcount correct.

Here's a simple test case, I tried it with msvc 9:

#include "boost/function.hpp"

int instances=0;
struct X
        X() { ++instances; }
        X(X const &) { ++instances; }
        ~X() { --instances; }
        void operator()() { }
boost::function<void()> f() { return X(); }

int main( int argc, char const * argv[] )
        boost::function<void()> f2;

Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at