Fix ptr<> nested release()

Fix a bug with ptr<> that at some occasions will try to free _ref
multiple times when release() becomes nested.
This commit is contained in:
Daniel Adolfsson 2011-09-14 10:51:25 +02:00
parent 5efe4124d7
commit 77b328ad15

View File

@ -49,8 +49,6 @@ private:
_ref->ns = 1; _ref->ns = 1;
_ref->nw = 0; _ref->nw = 0;
_weak = false; _weak = false;
// DBG("acquire(T*) p=%x, count=%d", p, 1);
} }
} }
@ -68,8 +66,6 @@ private:
_ref->nw++; _ref->nw++;
else else
_ref->ns++; _ref->ns++;
// DBG("acquire(const ptr<T>&) p=%x, count=%d", _ref->p, _ref->count);
} }
} }
@ -78,17 +74,18 @@ private:
if(!_ref) if(!_ref)
return; return;
if(!_weak && _ref->ns) if(_weak)
_ref->nw--;
else if(_ref->ns)
{ {
if(!--_ref->ns && _ref->p) if((_ref->ns == 1) && _ref->p)
{ {
delete _ref->p; delete _ref->p;
_ref->p = 0; _ref->p = 0;
} }
}
if(_weak) _ref->ns--;
_ref->nw--; }
if(!_ref->ns && !_ref->nw) if(!_ref->ns && !_ref->nw)
delete _ref; delete _ref;