Fix a bug with ptr<> that at some occasions will try to free _ref multiple times when release() becomes nested.