Forráskód Böngészése

Fixed reference counting of ctkServiceRegistrationPrivate.

Sascha Zelzer 13 éve
szülő
commit
0072a44213

+ 8 - 0
Libs/PluginFramework/ctkServiceReferencePrivate.cpp

@@ -37,6 +37,14 @@
 ctkServiceReferencePrivate::ctkServiceReferencePrivate(ctkServiceRegistrationPrivate* reg)
   : ref(1), registration(reg)
 {
+  if (registration) registration->ref.ref();
+}
+
+//----------------------------------------------------------------------------
+ctkServiceReferencePrivate::~ctkServiceReferencePrivate()
+{
+  if (registration && !registration->ref.deref())
+    delete registration;
 }
 
 //----------------------------------------------------------------------------

+ 1 - 1
Libs/PluginFramework/ctkServiceReferencePrivate.h

@@ -42,7 +42,7 @@ public:
 
   ctkServiceReferencePrivate(ctkServiceRegistrationPrivate* reg);
 
-  virtual ~ctkServiceReferencePrivate() {}
+  ~ctkServiceReferencePrivate();
 
   /**
     * Get the service object.

+ 7 - 0
Libs/PluginFramework/ctkServiceRegistrationPrivate.h

@@ -43,6 +43,13 @@ protected:
 
   friend class ctkServiceRegistration;
 
+  // The ctkServiceReferencePrivate class holds a pointer to a
+  // ctkServiceRegistrationPrivate instance and needs to manipulate
+  // its reference count. This way it can keep the ctkServiceRegistrationPrivate
+  // instance alive and keep returning service properties for
+  // unregistered service instances.
+  friend class ctkServiceReferencePrivate;
+
   /**
    * Reference count for implicitly shared private implementation.
    */