celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From griccia...@apache.org
Subject celix git commit: Fixed some Coverity issues
Date Tue, 03 Oct 2017 11:16:48 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 6818c4f57 -> 988a4c36c


Fixed some Coverity issues


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

Branch: refs/heads/develop
Commit: 988a4c36cd94483e56fc5c411e1bbb8dd82c5ddf
Parents: 6818c4f
Author: gricciardi <gricciardi@apache.org>
Authored: Tue Oct 3 13:16:24 2017 +0200
Committer: gricciardi <gricciardi@apache.org>
Committed: Tue Oct 3 13:16:24 2017 +0200

----------------------------------------------------------------------
 .../private/include/pubsub_admin_impl.h         |  1 +
 .../private/src/pubsub_admin_impl.c             | 33 ++++++++++--------
 .../private/include/pubsub_admin_impl.h         |  1 +
 .../private/src/pubsub_admin_impl.c             | 35 ++++++++++++--------
 4 files changed, 42 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/988a4c36/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h b/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h
index 7696722..de4b813 100644
--- a/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h
+++ b/pubsub/pubsub_admin_udp_mc/private/include/pubsub_admin_impl.h
@@ -56,6 +56,7 @@ struct pubsub_admin {
 
 	/* Those are used to keep track of valid subscriptions/publications that still have no valid
serializer */
 	celix_thread_mutex_t noSerializerPendingsLock;
+	celix_thread_mutexattr_t noSerializerPendingsAttr;
 	array_list_pt noSerializerSubscriptions; // List<pubsub_ep>
 	array_list_pt noSerializerPublications; // List<pubsub_ep>
 

http://git-wip-us.apache.org/repos/asf/celix/blob/988a4c36/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c b/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c
index c3136f9..a582c22 100644
--- a/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c
+++ b/pubsub/pubsub_admin_udp_mc/private/src/pubsub_admin_impl.c
@@ -179,10 +179,13 @@ celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt
*ad
 	celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL);
 	celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL);
 	celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL);
-	celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, NULL);
 	celixThreadMutex_create(&(*admin)->serializerListLock, NULL);
 	celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL);
 
+	celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr);
+	celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+	celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr);
+
 	celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr);
 	celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
 	celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr);
@@ -272,9 +275,11 @@ celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
 	celixThreadMutex_unlock(&admin->usedSerializersLock);
 
 	celixThreadMutex_destroy(&admin->usedSerializersLock);
-	celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
 	celixThreadMutex_destroy(&admin->serializerListLock);
 
+	celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
+	celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
+
 	celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);
 	celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
 
@@ -473,18 +478,19 @@ celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpo
 
 	printf("PSA_UDP_MC: Removing subscription [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->scope,
subEP->topic);
 
-	celixThreadMutex_lock(&admin->subscriptionsLock);
-
 	char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
-	topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
 
+	celixThreadMutex_lock(&admin->subscriptionsLock);
+	topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
 	if(sub!=NULL){
 		pubsub_topicDecreaseNrSubscribers(sub);
 		if(pubsub_topicGetNrSubscribers(sub) == 0) {
 			status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
 		}
 	}
-	else{
+	celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+	if(sub==NULL){
 		/* Maybe the endpoint was pending */
 		celixThreadMutex_lock(&admin->noSerializerPendingsLock);
 		if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
@@ -495,7 +501,7 @@ celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpo
 
 	free(scope_topic);
 
-	celixThreadMutex_unlock(&admin->subscriptionsLock);
+
 
 	return status;
 
@@ -625,13 +631,14 @@ celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoi
 	if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
 
 		celixThreadMutex_lock(&admin->localPublicationsLock);
-
 		service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
 		if(factory!=NULL){
 			topic_publication_pt pub = (topic_publication_pt)factory->handle;
 			pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
 		}
-		else{
+		celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+		if(factory==NULL){
 			/* Maybe the endpoint was pending */
 			celixThreadMutex_lock(&admin->noSerializerPendingsLock);
 			if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
@@ -640,7 +647,6 @@ celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoi
 			celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
 		}
 
-		celixThreadMutex_unlock(&admin->localPublicationsLock);
 	}
 	else{
 
@@ -860,11 +866,11 @@ celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt
 	}
 
 	celixThreadMutex_lock(&admin->serializerListLock);
-	celixThreadMutex_lock(&admin->usedSerializersLock);
-
-
 	/* Remove the serializer from the list */
 	arrayList_removeElement(admin->serializerList, reference);
+	celixThreadMutex_unlock(&admin->serializerListLock);
+
+	celixThreadMutex_lock(&admin->usedSerializersLock);
 
 	/* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the
noSerializer pending list */
 	array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer,
service);
@@ -969,7 +975,6 @@ celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt
 	}
 
 	celixThreadMutex_unlock(&admin->usedSerializersLock);
-	celixThreadMutex_unlock(&admin->serializerListLock);
 
 	printf("PSA_UDP_MC: %s serializer removed\n",serType);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/988a4c36/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h b/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h
index a18e9cf..03e8556 100644
--- a/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h
+++ b/pubsub/pubsub_admin_zmq/private/include/pubsub_admin_impl.h
@@ -73,6 +73,7 @@ struct pubsub_admin {
 
 	/* Those are used to keep track of valid subscriptions/publications that still have no valid
serializer */
 	celix_thread_mutex_t noSerializerPendingsLock;
+	celix_thread_mutexattr_t noSerializerPendingsAttr;
 	array_list_pt noSerializerSubscriptions; // List<pubsub_ep>
 	array_list_pt noSerializerPublications; // List<pubsub_ep>
 

http://git-wip-us.apache.org/repos/asf/celix/blob/988a4c36/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c b/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
index efba13a..db3b762 100644
--- a/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
+++ b/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
@@ -107,10 +107,13 @@ celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt
*ad
 		celixThreadMutex_create(&(*admin)->localPublicationsLock, NULL);
 		celixThreadMutex_create(&(*admin)->subscriptionsLock, NULL);
 		celixThreadMutex_create(&(*admin)->externalPublicationsLock, NULL);
-		celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, NULL);
 		celixThreadMutex_create(&(*admin)->serializerListLock, NULL);
 		celixThreadMutex_create(&(*admin)->usedSerializersLock, NULL);
 
+		celixThreadMutexAttr_create(&(*admin)->noSerializerPendingsAttr);
+		celixThreadMutexAttr_settype(&(*admin)->noSerializerPendingsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
+		celixThreadMutex_create(&(*admin)->noSerializerPendingsLock, &(*admin)->noSerializerPendingsAttr);
+
 		celixThreadMutexAttr_create(&(*admin)->pendingSubscriptionsAttr);
 		celixThreadMutexAttr_settype(&(*admin)->pendingSubscriptionsAttr, CELIX_THREAD_MUTEX_RECURSIVE);
 		celixThreadMutex_create(&(*admin)->pendingSubscriptionsLock, &(*admin)->pendingSubscriptionsAttr);
@@ -267,10 +270,12 @@ celix_status_t pubsubAdmin_destroy(pubsub_admin_pt admin)
 	celixThreadMutex_unlock(&admin->usedSerializersLock);
 
 	celixThreadMutex_destroy(&admin->usedSerializersLock);
-	celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
 	celixThreadMutex_destroy(&admin->serializerListLock);
 	celixThreadMutex_destroy(&admin->pendingSubscriptionsLock);
 
+	celixThreadMutexAttr_destroy(&admin->noSerializerPendingsAttr);
+	celixThreadMutex_destroy(&admin->noSerializerPendingsLock);
+
 	celixThreadMutexAttr_destroy(&admin->pendingSubscriptionsAttr);
 	celixThreadMutex_destroy(&admin->subscriptionsLock);
 
@@ -474,18 +479,19 @@ celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpo
 
 	printf("PSA_ZMQ: Removing subscription [FWUUID=%s bundleID=%ld topic=%s]\n",subEP->frameworkUUID,subEP->serviceID,subEP->topic);
 
-	celixThreadMutex_lock(&admin->subscriptionsLock);
-
 	char* scope_topic = createScopeTopicKey(subEP->scope, subEP->topic);
-	topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
 
+	celixThreadMutex_lock(&admin->subscriptionsLock);
+	topic_subscription_pt sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,scope_topic);
 	if(sub!=NULL){
 		pubsub_topicDecreaseNrSubscribers(sub);
 		if(pubsub_topicGetNrSubscribers(sub) == 0) {
 			status = pubsub_topicSubscriptionRemoveSubscriber(sub,subEP);
 		}
 	}
-	else{
+	celixThreadMutex_unlock(&admin->subscriptionsLock);
+
+	if(sub==NULL){
 		/* Maybe the endpoint was pending */
 		celixThreadMutex_lock(&admin->noSerializerPendingsLock);
 		if(!arrayList_removeElement(admin->noSerializerSubscriptions, subEP)){
@@ -496,7 +502,7 @@ celix_status_t pubsubAdmin_removeSubscription(pubsub_admin_pt admin,pubsub_endpo
 
 	free(scope_topic);
 
-	celixThreadMutex_unlock(&admin->subscriptionsLock);
+
 
 	return status;
 
@@ -627,13 +633,14 @@ celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoi
 	if(strcmp(pubEP->frameworkUUID,fwUUID)==0){
 
 		celixThreadMutex_lock(&admin->localPublicationsLock);
-
 		service_factory_pt factory = (service_factory_pt)hashMap_get(admin->localPublications,scope_topic);
 		if(factory!=NULL){
 			topic_publication_pt pub = (topic_publication_pt)factory->handle;
 			pubsub_topicPublicationRemovePublisherEP(pub,pubEP);
 		}
-		else{
+		celixThreadMutex_unlock(&admin->localPublicationsLock);
+
+		if(factory==NULL){
 			/* Maybe the endpoint was pending */
 			celixThreadMutex_lock(&admin->noSerializerPendingsLock);
 			if(!arrayList_removeElement(admin->noSerializerPublications, pubEP)){
@@ -642,7 +649,7 @@ celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoi
 			celixThreadMutex_unlock(&admin->noSerializerPendingsLock);
 		}
 
-		celixThreadMutex_unlock(&admin->localPublicationsLock);
+
 	}
 	else{
 
@@ -859,11 +866,12 @@ celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt
 	}
 
 	celixThreadMutex_lock(&admin->serializerListLock);
-	celixThreadMutex_lock(&admin->usedSerializersLock);
-
-
 	/* Remove the serializer from the list */
 	arrayList_removeElement(admin->serializerList, reference);
+	celixThreadMutex_unlock(&admin->serializerListLock);
+
+
+	celixThreadMutex_lock(&admin->usedSerializersLock);
 
 	/* Now destroy the topicPublications, but first put back the pubsub_endpoints back to the
noSerializer pending list */
 	array_list_pt topicPubList = (array_list_pt)hashMap_remove(admin->topicPublicationsPerSerializer,
service);
@@ -968,7 +976,6 @@ celix_status_t pubsubAdmin_serializerRemoved(void * handle, service_reference_pt
 	}
 
 	celixThreadMutex_unlock(&admin->usedSerializersLock);
-	celixThreadMutex_unlock(&admin->serializerListLock);
 
 	printf("PSA_ZMQ: %s serializer removed\n",serType);
 


Mime
View raw message