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 Fri, 29 Sep 2017 15:44:50 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 42545f1a9 -> 76882849a


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/76882849
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/76882849
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/76882849

Branch: refs/heads/develop
Commit: 76882849ac2e992c2cd6c7dc1d1dae00a651bfc3
Parents: 42545f1
Author: gricciardi <gricciardi@apache.org>
Authored: Fri Sep 29 17:44:39 2017 +0200
Committer: gricciardi <gricciardi@apache.org>
Committed: Fri Sep 29 17:44:39 2017 +0200

----------------------------------------------------------------------
 .../private/src/pubsub_admin_impl.c             | 10 ++++-----
 .../private/src/pubsub_admin_impl.c             |  8 +++----
 .../pubsub_common/public/src/pubsub_endpoint.c  | 17 +++++++++++----
 .../private/src/pstm_activator.c                | 23 +++++++++++++++-----
 4 files changed, 38 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/76882849/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 8268287..5a651da 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
@@ -144,6 +144,7 @@ celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt
*ad
 			char loop = 1;
 			if(setsockopt(sendSocket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) != 0)
{
 				perror("pubsubAdmin_create:setsockopt(IP_MULTICAST_LOOP)");
+				close(sendSocket);
 				return CELIX_SERVICE_EXCEPTION;
 			}
 
@@ -151,6 +152,7 @@ celix_status_t pubsubAdmin_create(bundle_context_pt context, pubsub_admin_pt
*ad
 			inet_aton(if_ip, &multicast_interface);
 			if(setsockopt(sendSocket,  IPPROTO_IP, IP_MULTICAST_IF, &multicast_interface, sizeof(multicast_interface))
!= 0) {
 				perror("pubsubAdmin_create:setsockopt(IP_MULTICAST_IF)");
+				close(sendSocket);
 				return CELIX_SERVICE_EXCEPTION;
 			}
 
@@ -679,9 +681,8 @@ celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,char
*scop
 		service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
 		topic_publication_pt pub = (topic_publication_pt)factory->handle;
 		status += pubsub_topicPublicationStop(pub);
-		status += pubsub_topicPublicationDestroy(pub);
-
 		disconnectTopicPubSubFromSerializer(admin, pub, true);
+		status += pubsub_topicPublicationDestroy(pub);
 		hashMap_remove(admin->localPublications,scope_topic);
 		free(key);
 		free(factory);
@@ -706,9 +707,8 @@ celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char
*sco
 
 		topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
 		status += pubsub_topicSubscriptionStop(ts);
-		status += pubsub_topicSubscriptionDestroy(ts);
-
 		disconnectTopicPubSubFromSerializer(admin, ts, false);
+		status += pubsub_topicSubscriptionDestroy(ts);
 		hashMap_remove(admin->subscriptions,topic);
 		free(topic);
 
@@ -749,9 +749,7 @@ static celix_status_t pubsubAdmin_getIpAddress(const char* interface,
char** ip)
 
 		freeifaddrs(ifaddr);
 	}
-	if(status == CELIX_SUCCESS) {
 
-	}
 	return status;
 }
 #endif

http://git-wip-us.apache.org/repos/asf/celix/blob/76882849/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 9316506..522b2a5 100644
--- a/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
+++ b/pubsub/pubsub_admin_zmq/private/src/pubsub_admin_impl.c
@@ -682,7 +682,7 @@ celix_status_t pubsubAdmin_removePublication(pubsub_admin_pt admin,pubsub_endpoi
 	/* And check also for ANY subscription */
 	topic_subscription_pt any_sub = (topic_subscription_pt)hashMap_get(admin->subscriptions,PUBSUB_ANY_SUB_TOPIC);
 	if(any_sub!=NULL && pubEP->endpoint!=NULL && count == 0){
-		pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(sub,pubEP->endpoint);
+		pubsub_topicSubscriptionAddDisconnectPublisherToPendingList(any_sub,pubEP->endpoint);
 	}
 
 	free(scope_topic);
@@ -705,9 +705,8 @@ celix_status_t pubsubAdmin_closeAllPublications(pubsub_admin_pt admin,
char *sco
 		service_factory_pt factory= (service_factory_pt)hashMapEntry_getValue(pubsvc_entry);
 		topic_publication_pt pub = (topic_publication_pt)factory->handle;
 		status += pubsub_topicPublicationStop(pub);
-		status += pubsub_topicPublicationDestroy(pub);
-
 		disconnectTopicPubSubFromSerializer(admin, pub, true);
+		status += pubsub_topicPublicationDestroy(pub);
 		hashMap_remove(admin->localPublications,scope_topic);
 		free(key);
 		free(factory);
@@ -732,9 +731,8 @@ celix_status_t pubsubAdmin_closeAllSubscriptions(pubsub_admin_pt admin,char*
sco
 
 		topic_subscription_pt ts = (topic_subscription_pt)hashMapEntry_getValue(sub_entry);
 		status += pubsub_topicSubscriptionStop(ts);
-		status += pubsub_topicSubscriptionDestroy(ts);
-
 		disconnectTopicPubSubFromSerializer(admin, ts, false);
+		status += pubsub_topicSubscriptionDestroy(ts);
 		hashMap_remove(admin->subscriptions,scope_topic);
 		free(topic);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/76882849/pubsub/pubsub_common/public/src/pubsub_endpoint.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_common/public/src/pubsub_endpoint.c b/pubsub/pubsub_common/public/src/pubsub_endpoint.c
index f6776d5..c3fd293 100644
--- a/pubsub/pubsub_common/public/src/pubsub_endpoint.c
+++ b/pubsub/pubsub_common/public/src/pubsub_endpoint.c
@@ -127,7 +127,7 @@ celix_status_t pubsubEndpoint_clone(pubsub_endpoint_pt in, pubsub_endpoint_pt
*o
 celix_status_t pubsubEndpoint_createFromServiceReference(service_reference_pt reference,
pubsub_endpoint_pt* psEp, bool isPublisher){
 	celix_status_t status = CELIX_SUCCESS;
 
-	*psEp = calloc(1,sizeof(**psEp));
+	pubsub_endpoint_pt ep = calloc(1,sizeof(*ep));
 
 	bundle_pt bundle = NULL;
 	bundle_context_pt ctxt = NULL;
@@ -148,11 +148,16 @@ celix_status_t pubsubEndpoint_createFromServiceReference(service_reference_pt
re
 	/* TODO: is topic_props==NULL a fatal error such that EP cannot be created? */
 	properties_pt topic_props = pubsubEndpoint_getTopicProperties(bundle, topic, isPublisher);
 
-	pubsubEndpoint_setFields(*psEp, fwUUID, scope!=NULL?scope:PUBSUB_SUBSCRIBER_SCOPE_DEFAULT,
topic, strtol(serviceId,NULL,10), NULL, topic_props, false);
+	pubsubEndpoint_setFields(ep, fwUUID, scope!=NULL?scope:PUBSUB_SUBSCRIBER_SCOPE_DEFAULT,
topic, strtol(serviceId,NULL,10), NULL, topic_props, false);
 
-	if (!(*psEp)->frameworkUUID || !(*psEp)->serviceID || !(*psEp)->scope || !(*psEp)->topic)
{
+	if (!ep->frameworkUUID || !ep->serviceID || !ep->scope || !ep->topic) {
 		fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "PUBSUB_ENDPOINT: incomplete description!.");
 		status = CELIX_BUNDLE_EXCEPTION;
+		pubsubEndpoint_destroy(ep);
+		*psEp = NULL;
+	}
+	else{
+		*psEp = ep;
 	}
 
 	return status;
@@ -165,8 +170,12 @@ celix_status_t pubsubEndpoint_createFromListenerHookInfo(listener_hook_info_pt
i
 	const char* fwUUID=NULL;
 	bundleContext_getProperty(info->context,OSGI_FRAMEWORK_FRAMEWORK_UUID,&fwUUID);
 
+	if(fwUUID==NULL){
+		return CELIX_BUNDLE_EXCEPTION;
+	}
+
 	char* topic = pubsub_getTopicFromFilter(info->filter);
-	if(topic==NULL || fwUUID==NULL){
+	if(topic==NULL){
 		return CELIX_BUNDLE_EXCEPTION;
 	}
 

http://git-wip-us.apache.org/repos/asf/celix/blob/76882849/pubsub/pubsub_topology_manager/private/src/pstm_activator.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_topology_manager/private/src/pstm_activator.c b/pubsub/pubsub_topology_manager/private/src/pstm_activator.c
index 0ce2571..4d6dd27 100644
--- a/pubsub/pubsub_topology_manager/private/src/pstm_activator.c
+++ b/pubsub/pubsub_topology_manager/private/src/pstm_activator.c
@@ -153,6 +153,10 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void
**userData
 		}
 	}
 
+	if(status != CELIX_SUCCESS){
+		bundleActivator_destroy(activator, context);
+	}
+
 	return status;
 }
 
@@ -214,18 +218,27 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt
contex
 	celix_status_t status = CELIX_SUCCESS;
 
 	struct activator *activator = userData;
-	if (!activator || !activator->manager) {
+	if (activator == NULL) {
 		status = CELIX_BUNDLE_EXCEPTION;
 	} else {
 
-		serviceTracker_destroy(activator->pubsubSubscribersTracker);
-		serviceTracker_destroy(activator->pubsubDiscoveryTracker);
-		serviceTracker_destroy(activator->pubsubAdminTracker);
+		if(activator->pubsubSubscribersTracker!=NULL){
+			serviceTracker_destroy(activator->pubsubSubscribersTracker);
+		}
+		if(activator->pubsubDiscoveryTracker!=NULL){
+			serviceTracker_destroy(activator->pubsubDiscoveryTracker);
+		}
+		if(activator->pubsubAdminTracker!=NULL){
+			serviceTracker_destroy(activator->pubsubAdminTracker);
+		}
+
+		if(activator->manager!=NULL){
+			status = pubsub_topologyManager_destroy(activator->manager);
+		}
 
 		logHelper_stop(activator->loghelper);
 		logHelper_destroy(&activator->loghelper);
 
-		status = pubsub_topologyManager_destroy(activator->manager);
 		free(activator);
 	}
 


Mime
View raw message