From 4a5bcf0f7a069e4f97493d0c881ddac2f049a80a Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 5 Dec 2012 20:02:30 -0500 Subject: [PATCH] Rework debugging check in BReferenceable. - If a BReferenceable object is deleted with a non-zero reference count, we now test to see if the object was allocated on the stack. If so, we don't flag a warning if the reference count is currently 1. --- src/kits/support/Referenceable.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/kits/support/Referenceable.cpp b/src/kits/support/Referenceable.cpp index 6b2ee363b0..39cc641f33 100644 --- a/src/kits/support/Referenceable.cpp +++ b/src/kits/support/Referenceable.cpp @@ -27,8 +27,18 @@ BReferenceable::BReferenceable() BReferenceable::~BReferenceable() { #ifdef DEBUG - if (fReferenceCount > 1) - debugger("Deleted object which still had references.\n"); + if (fReferenceCount != 0) { + // Simple heuristic to test if this object was allocated + // on the stack: check if this is within 1KB in either + // direction of the current stack address, and the reference + // count is 1. If so, we don't flag a warning since that would + // imply the object was allocated/destroyed on the stack + // without any references being acquired or released. + char test; + int64 testOffset = (int64)this - (int64)&test; + if (testOffset < -1024 || testOffset > 1024 || fReferenceCount != 1) + debugger("Deleted referenceable object with non-zero ref count."); + } #endif }