You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2018/10/15 11:18:17 UTC

celix git commit: CELIX-454: Fixes some mem leaks, correct cleanup for service listeners and ensures that onlye a single framework shutdown thread will be started for multiple shutdown requests.

Repository: celix
Updated Branches:
  refs/heads/develop d0b190250 -> c3f2e8205


CELIX-454: Fixes some mem leaks, correct cleanup for service listeners and ensures that onlye a single framework shutdown thread will be started for multiple shutdown requests.


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/c3f2e820
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/c3f2e820
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/c3f2e820

Branch: refs/heads/develop
Commit: c3f2e82056963ca2078681b47a028ce4e9995fe1
Parents: d0b1902
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Mon Oct 15 13:16:55 2018 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Mon Oct 15 13:16:55 2018 +0200

----------------------------------------------------------------------
 .../pubsub/pubsub_spi/src/pubsub_utils_match.c  |  1 +
 .../src/pubsub_topology_manager.c               |  1 +
 libs/framework/src/framework.c                  | 26 +++++++++++++++-----
 libs/framework/src/framework_private.h          |  1 +
 libs/framework/src/service_registry.c           | 14 +++++++----
 5 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/c3f2e820/bundles/pubsub/pubsub_spi/src/pubsub_utils_match.c
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_spi/src/pubsub_utils_match.c b/bundles/pubsub/pubsub_spi/src/pubsub_utils_match.c
index 945ddf0..9f303ba 100644
--- a/bundles/pubsub/pubsub_spi/src/pubsub_utils_match.c
+++ b/bundles/pubsub/pubsub_spi/src/pubsub_utils_match.c
@@ -173,6 +173,7 @@ double pubsub_utils_matchSubscriber(
 	if (ep != NULL) {
 		requested_admin = celix_properties_get(ep, PUBSUB_ENDPOINT_ADMIN_TYPE, NULL);
 		requested_qos = celix_properties_get(ep, PUBSUB_UTILS_QOS_ATTRIBUTE_KEY, NULL);
+		celix_properties_destroy(ep);
 	}
 
 	double score = getPSAScore(requested_admin, requested_qos, adminType, sampleScore, controlScore, defaultScore);

http://git-wip-us.apache.org/repos/asf/celix/blob/c3f2e820/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
----------------------------------------------------------------------
diff --git a/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c b/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
index fe32ae7..df7b005 100644
--- a/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
+++ b/bundles/pubsub/pubsub_topology_manager/src/pubsub_topology_manager.c
@@ -440,6 +440,7 @@ void pubsub_topologyManager_publisherTrackerRemoved(void *handle, const celix_se
 	celixThreadMutex_unlock(&manager->topicSenders.mutex);
 
 	free(scopeAndTopicKey);
+	free(topic);
 	free(scopeFromFilter);
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/c3f2e820/libs/framework/src/framework.c
----------------------------------------------------------------------
diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c
index 54fe8d3..75c61e8 100644
--- a/libs/framework/src/framework.c
+++ b/libs/framework/src/framework.c
@@ -376,6 +376,7 @@ celix_status_t framework_create(framework_pt *framework, properties_pt config) {
             (*framework)->bundle = NULL;
             (*framework)->registry = NULL;
             (*framework)->shutdown.done = false;
+            (*framework)->shutdown.initialized = false;
             (*framework)->dispatcher.active = true;
             (*framework)->nextBundleId = 1L; //system bundle is 0
             (*framework)->cache = NULL;
@@ -471,6 +472,12 @@ celix_status_t framework_destroy(framework_pt framework) {
 	serviceRegistry_destroy(framework->registry);
 
     if (framework->serviceListeners != NULL) {
+        int size = celix_arrayList_size(framework->serviceListeners);
+        for (int i = 0; i < size; ++i) {
+            celix_fw_service_listener_entry_t *entry = celix_arrayList_get(framework->serviceListeners, i);
+            listener_release(entry);
+            listener_waitAndDestroy(framework, entry);
+        }
         arrayList_destroy(framework->serviceListeners);
     }
     if (framework->bundleListeners) {
@@ -2419,13 +2426,20 @@ static celix_status_t frameworkActivator_stop(void * userData, bundle_context_t
 
 	    fw_log(framework->logger, OSGI_FRAMEWORK_LOG_DEBUG, "FRAMEWORK: Start shutdownthread");
 
-        celixThreadMutex_lock(&framework->dispatcher.mutex);
-        framework->dispatcher.active = false;
-        celixThreadCondition_broadcast(&framework->dispatcher.cond);
-        celixThreadMutex_unlock(&framework->dispatcher.mutex);
-        celixThread_join(framework->dispatcher.thread, NULL);
+	    celixThreadMutex_lock(&framework->shutdown.mutex);
+	    bool alreadyIntialized = framework->shutdown.initialized;
+	    framework->shutdown.initialized = true;
+        celixThreadMutex_unlock(&framework->shutdown.mutex);
 
-        celixThread_create(&framework->shutdown.thread, NULL, &framework_shutdown, framework);
+        if (!alreadyIntialized) {
+            celixThreadMutex_lock(&framework->dispatcher.mutex);
+            framework->dispatcher.active = false;
+            celixThreadCondition_broadcast(&framework->dispatcher.cond);
+            celixThreadMutex_unlock(&framework->dispatcher.mutex);
+            celixThread_join(framework->dispatcher.thread, NULL);
+
+            celixThread_create(&framework->shutdown.thread, NULL, &framework_shutdown, framework);
+        }
 	} else {
 		status = CELIX_FRAMEWORK_EXCEPTION;
 	}

http://git-wip-us.apache.org/repos/asf/celix/blob/c3f2e820/libs/framework/src/framework_private.h
----------------------------------------------------------------------
diff --git a/libs/framework/src/framework_private.h b/libs/framework/src/framework_private.h
index babffd3..10bb26f 100644
--- a/libs/framework/src/framework_private.h
+++ b/libs/framework/src/framework_private.h
@@ -66,6 +66,7 @@ struct framework {
         celix_thread_mutex_t mutex;
         celix_thread_cond_t cond;
         bool done; //true is shutdown is done
+        bool initialized; //true is a shutdown is initialized
         celix_thread_t thread;
     } shutdown;
 

http://git-wip-us.apache.org/repos/asf/celix/blob/c3f2e820/libs/framework/src/service_registry.c
----------------------------------------------------------------------
diff --git a/libs/framework/src/service_registry.c b/libs/framework/src/service_registry.c
index 2a5ce82..62c0d2f 100644
--- a/libs/framework/src/service_registry.c
+++ b/libs/framework/src/service_registry.c
@@ -765,13 +765,17 @@ celix_status_t serviceRegistry_getListenerHooks(service_registry_pt registry, bu
         for (i = 0; i < size; i += 1) {
             celixThreadRwlock_readLock(&registry->lock);
             service_registration_pt registration = arrayList_get(registry->listenerHooks, i);
-            serviceRegistration_retain(registration);
+            if (registration != NULL) {
+                serviceRegistration_retain(registration);
+            }
             celixThreadRwlock_unlock(&registry->lock);
 
-            service_reference_pt reference = NULL;
-            serviceRegistry_getServiceReference(registry, owner, registration, &reference);
-            arrayList_add(result, reference);
-            serviceRegistration_release(registration);
+            if (registration != NULL) {
+                service_reference_pt reference = NULL;
+                serviceRegistry_getServiceReference(registry, owner, registration, &reference);
+                arrayList_add(result, reference);
+                serviceRegistration_release(registration);
+            }
         }
     }