Просмотр исходного кода

Merge branch 'fix-pluginfw-memory-leaks'

* fix-pluginfw-memory-leaks:
  Break cyclic dependency by explicitly setting ref to 0.
  Removed unnecessary null check.
  Check for null pointer prior to modifying the ref count.
  Disable copy and assignment operators.
Sascha Zelzer лет назад: 14
Родитель
Сommit
8c5711d74b

+ 1 - 1
Libs/PluginFramework/ctkServiceReference.cpp

@@ -61,7 +61,7 @@ ctkServiceReference& ctkServiceReference::operator=(int null)
 {
 {
   if (null == 0)
   if (null == 0)
   {
   {
-    if (d_func() && !d_func()->ref.deref())
+    if (!d_func()->ref.deref())
       delete d_ptr;
       delete d_ptr;
     d_ptr = new ctkServiceReferencePrivate(0);
     d_ptr = new ctkServiceReferencePrivate(0);
   }
   }

+ 4 - 0
Libs/PluginFramework/ctkServiceReferencePrivate.h

@@ -103,6 +103,10 @@ public:
    * Link to registration object for this reference.
    * Link to registration object for this reference.
    */
    */
   ctkServiceRegistrationPrivate* const registration;
   ctkServiceRegistrationPrivate* const registration;
+
+private:
+
+  Q_DISABLE_COPY(ctkServiceReferencePrivate)
 };
 };
 
 
 #endif // CTKSERVICEREFERENCEPRIVATE_H
 #endif // CTKSERVICEREFERENCEPRIVATE_H

+ 4 - 3
Libs/PluginFramework/ctkServiceRegistration.cpp

@@ -51,7 +51,7 @@ ctkServiceRegistration::ctkServiceRegistration(const ctkServiceRegistration& reg
 ctkServiceRegistration::ctkServiceRegistration(ctkServiceRegistrationPrivate* registrationPrivate)
 ctkServiceRegistration::ctkServiceRegistration(ctkServiceRegistrationPrivate* registrationPrivate)
   : d_ptr(registrationPrivate)
   : d_ptr(registrationPrivate)
 {
 {
-  d_func()->ref.ref();
+  if(d_func()) d_func()->ref.ref();
 }
 }
 
 
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
@@ -202,7 +202,8 @@ void ctkServiceRegistration::unregister()
       d->plugin = 0;
       d->plugin = 0;
       d->dependents.clear();
       d->dependents.clear();
       d->service = 0;
       d->service = 0;
-      d->serviceInstances.clear();;
+      d->serviceInstances.clear();
+      d->reference = 0;
       d->unregistering = false;
       d->unregistering = false;
     }
     }
   }
   }
@@ -228,7 +229,7 @@ ctkServiceRegistration& ctkServiceRegistration::operator=(const ctkServiceRegist
 {
 {
   ctkServiceRegistrationPrivate* curr_d = d_func();
   ctkServiceRegistrationPrivate* curr_d = d_func();
   d_ptr = registration.d_ptr;
   d_ptr = registration.d_ptr;
-  d_ptr->ref.ref();
+  if (d_ptr) d_ptr->ref.ref();
 
 
   if (curr_d && !curr_d->ref.deref())
   if (curr_d && !curr_d->ref.deref())
     delete curr_d;
     delete curr_d;

+ 4 - 0
Libs/PluginFramework/ctkServiceRegistrationPrivate.h

@@ -123,6 +123,10 @@ public:
 
 
   virtual QObject* getService();
   virtual QObject* getService();
 
 
+private:
+
+  Q_DISABLE_COPY(ctkServiceRegistrationPrivate)
+
 };
 };