koffice/krita/image

Cyrille Berger cyb at lepi.org
Sun Jan 31 17:08:57 CET 2010


SVN commit 1083090 by berger:

Introduce a debug tool to check when we are leaking smart pointers. It
dumps all the leaks, and where the pointer was referenced at exit of
Krita.

It should only be enabled on debug mode. And for performance reason, it
does not use KDE's kbacktrace command, but only does symbol resolution
at exit. Because of this it is linux only (and I have no idea if it is
even possible on other platforms). So if you run into problem, tell me and I will fix them ASAP.

CC:kimageshop at kde.org



 M  +1 -0      CMakeLists.txt  
 AM            kis_memory_leak_tracker.cpp   [License: LGPL (v2+)]
 AM            kis_memory_leak_tracker.h   [License: LGPL (v2+)]
 M  +25 -7     kis_shared_ptr.h  


--- trunk/koffice/krita/image/CMakeLists.txt #1083089:1083090
@@ -121,6 +121,7 @@
    kis_rect_mask_generator.cpp
    kis_circle_mask_generator.cpp
    kis_math_toolbox.cpp
+   kis_memory_leak_tracker.cpp
    kis_merge_visitor.cpp
    kis_name_server.cpp
    kis_node.cpp
** trunk/koffice/krita/image/kis_memory_leak_tracker.cpp #property svn:eol-style
   + native
** trunk/koffice/krita/image/kis_memory_leak_tracker.cpp #property svn:keywords
   + Id
** trunk/koffice/krita/image/kis_memory_leak_tracker.h #property svn:eol-style
   + native
** trunk/koffice/krita/image/kis_memory_leak_tracker.h #property svn:keywords
   + Id
--- trunk/koffice/krita/image/kis_shared_ptr.h #1083089:1083090
@@ -1,6 +1,6 @@
 /*
  *  Copyright (c) 2005 Frerich Raabe <raabe at kde.org>
- *  Copyright (c) 2006 Cyrille Berger <cberger at cberger.net>
+ *  Copyright (c) 2006,2010 Cyrille Berger <cberger at cberger.net>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -26,6 +26,10 @@
 
 #include <kis_shared_data.h>
 
+#ifndef NDEBUG
+#include "kis_memory_leak_tracker.h"
+#endif
+
 template<class T>
 class KisWeakSharedPtr;
 
@@ -81,7 +85,7 @@
      */
     inline KisSharedPtr(T* p)
             : d(p) {
-        if (d) d->ref.ref();
+        if (d) ref();
     }
 
     inline KisSharedPtr(const KisWeakSharedPtr<T>& o);
@@ -92,7 +96,7 @@
      */
     inline KisSharedPtr<T>(const KisSharedPtr<T>& o)
             : d(o.d) {
-        if (d) d->ref.ref();
+        if (d) ref();
     }
 
     /**
@@ -100,7 +104,7 @@
      * the last reference, the object will be deleted.
      */
     inline ~KisSharedPtr() {
-        if (d && !d->ref.deref()) {
+        if (d && !deref()) {
             delete d;
         }
     }
@@ -197,8 +201,22 @@
     inline bool isNull() const {
         return (d == 0);
     }
-
 private:
+    inline bool ref() const
+    {
+#ifndef NDEBUG
+        KisMemoryLeakTracker::instance()->reference(d, this);
+#endif
+        return d->ref.ref();
+    }
+    inline bool deref() const
+    {
+#ifndef NDEBUG
+        KisMemoryLeakTracker::instance()->dereference(d, this);
+#endif
+        return d->ref.deref();
+    }
+private:
     mutable T* d;
 };
 
@@ -350,7 +368,7 @@
         : d(o.d)
 {
     Q_ASSERT(!o.dataPtr || (o.dataPtr && o.dataPtr->valid));
-    if (d) d->ref.ref();
+    if (d) ref();
 }
 
 
@@ -359,7 +377,7 @@
 {
     if (d != p) {
         if (p) p->ref.ref();
-        if (d && !d->ref.deref())
+        if (d && !deref())
             delete d;
         d = p;
     }


More information about the kimageshop mailing list