diff --git a/mfbt/RefPtr.h b/mfbt/RefPtr.h index 15ace62ef8b0..cf8e3c91081b 100644 --- a/mfbt/RefPtr.h +++ b/mfbt/RefPtr.h @@ -36,19 +36,23 @@ template OutParamRef byRef(RefPtr&); * live RefCounted are controlled by RefPtr and * RefPtr. Upon a transition from refcounted==1 * to 0, the RefCounted "dies" and is destroyed. The "destroyed" - * state is represented in DEBUG builds by refcount==-0xdead. This + * state is represented in DEBUG builds by refcount==0xffffdead. This * state distinguishes use-before-ref (refcount==0) from - * use-after-destroy (refcount==-0xdead). + * use-after-destroy (refcount==0xffffdead). */ template class RefCounted { friend class RefPtr; - public: +#ifdef DEBUG + static const int dead = 0xffffdead; +#endif + protected: RefCounted() : refCnt(0) { } - ~RefCounted() { MOZ_ASSERT(refCnt == -0xdead); } + ~RefCounted() { MOZ_ASSERT(refCnt == dead); } + public: // Compatibility with nsRefPtr. void AddRef() { MOZ_ASSERT(refCnt >= 0); @@ -59,7 +63,7 @@ class RefCounted MOZ_ASSERT(refCnt > 0); if (0 == --refCnt) { #ifdef DEBUG - refCnt = -0xdead; + refCnt = dead; #endif delete static_cast(this); }