[telepathy-qt4/master] shared-ptr: Make sure we WeakPtr deletes wd on operator=(SharedPtr).

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Mon Apr 6 10:33:01 PDT 2009


---
 TelepathyQt4/shared-ptr.h |   32 ++++++++++++++------------------
 1 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/TelepathyQt4/shared-ptr.h b/TelepathyQt4/shared-ptr.h
index 7d2518c..d90f012 100644
--- a/TelepathyQt4/shared-ptr.h
+++ b/TelepathyQt4/shared-ptr.h
@@ -168,12 +168,7 @@ public:
     }
     inline ~WeakPtr()
     {
-        if (wd && !wd->weakref.deref()) {
-            if (wd->d) {
-                wd->d->wd = 0;
-            }
-            delete wd;
-        }
+        deref();
     }
 
     inline bool isNull() const { return !wd || !wd->d || wd->d->strongref == 0; }
@@ -186,12 +181,7 @@ public:
             if (o.wd) {
                 o.wd->weakref.ref();
             }
-            if (wd && !wd->weakref.deref()) {
-                if (wd->d) {
-                    wd->d->wd = 0;
-                }
-                delete wd;
-            }
+            deref();
             wd = o.wd;
         }
         return *this;
@@ -205,15 +195,11 @@ public:
                     o.d->wd = new WeakData(o.d);
                 }
                 o.d->wd->weakref.ref();
-                if (wd && !wd->weakref.deref()) {
-                    if (wd->d) {
-                        wd->d->wd = 0;
-                    }
-                    delete wd;
-                }
+                deref();
                 wd = o.d->wd;
             }
         } else {
+            deref();
             wd = 0;
         }
         return *this;
@@ -222,6 +208,16 @@ public:
 private:
     friend class SharedPtr<T>;
 
+    inline void deref()
+    {
+        if (wd && !wd->weakref.deref()) {
+            if (wd->d) {
+                wd->d->wd = 0;
+            }
+            delete wd;
+        }
+    }
+
     WeakData *wd;
 };
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list