Boost logo

Boost Users :

From: Per Kristensen (per.kristensen_at_[hidden])
Date: 2002-11-11 16:54:06


This is a constructed test case which should illustrate the problem. The bug is only a problem if you access data members of the counted_based object after the call to delete. So you can live happy without knowing anything about the bug if you never do that.
 
//sourcecode begin
#include "boost/shared_ptr.hpp"
#include "boost/weak_ptr.hpp"
 
class foo {
public:
    void setWeak(boost::shared_ptr<foo> s) {
        w = s;
    }
private:
    boost::weak_ptr<foo> w; //the desctuction of this member will delete the counted_based object
};
 
class deleter {
public:
    deleter() :lock(0) {}
    ~deleter() {
        assert(lock==0); //assert if destructor is called when we are executing
    }
    void operator() (foo *p) {
        ++lock; //lock the object from destruction within this operation
        delete p;
        --lock;//unlock the object
    }
 
private:
    int lock;
};
 
void main() {
    boost::shared_ptr<foo> s(new foo,deleter());
    s->setWeak(s);
 
    s.reset();
 
}

//source code end

-----Original Message-----
From: Peter Dimov [mailto:pdimov_at_[hidden]]
Sent: 11. november 2002 21:43
To: Boost-Users_at_[hidden]
Subject: Re: [Boost-Users] BUG: counted_base::release

From: "perkristensennettest" <per.kristensen_at_[hidden]>
> To me it seems like a bug, that the weak_count in
> counted_base::release is decremented before the call to dispose. See
> below
[...]
>
> If the call to dispose() indirectly calls weak_release there is an
> error as weak_release will decrement the --weak_count and may
> destruct the counted_base object. This will happen if you have an
> class C with a member of type weak_ptr<C>.

Do you have a test case that breaks?

Info: < http://www.boost.org>
Wiki: < http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service <http://docs.yahoo.com/info/terms/> .

[Non-text portions of this message have been removed]


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