$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Serge Skorokhodov (serge.skorokhodov_at_[hidden])
Date: 2006-01-08 05:25:02
Pooyan McSporran wrote:
> (Using gcc 4.0.2, boost 1.33.1, linux)>
> I've got a program which causes segfaults using shared_ptr.  I've reduced
> the program as far as I can to show the fault without any extra fluff.  It
> looks as if an object pointed to by a shared_ptr is being deleted more than
> once.
<skip>
>   void test (MemoryPtr m) {
>     m -> remember1 (FooPtr (this));
Definetely a misuse. A poiner to a "newed" object or another
shared_ptr must be passed to share_ptr ctor. Actually, you are
baypassing reference counting here. "this" is neither:( Try this:
void test ( MemoryPtr m, FooPtr f )
{
  m->remember1( f );
}
>   }
<skip>
> int main ()
> {
>   {
>     FooPtr f1 (new Foo ("first"));
>     MemoryPtr m1 (new Memory ());
>     f1 -> test (m1);
and here:
      f1->test (m1, f1);
>   }
> 
>   return EXIT_SUCCESS;
> }