celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [1/2] celix git commit: CELIX-360: Fixes leftover coverity issues.
Date Wed, 04 May 2016 13:32:37 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 9176f035f -> f593c02e2


CELIX-360: Fixes leftover coverity issues.


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

Branch: refs/heads/develop
Commit: 74154abcabb0d2305cbeb95527487e1a6b08b479
Parents: 9176f03
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Wed May 4 15:29:03 2016 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Wed May 4 15:29:03 2016 +0200

----------------------------------------------------------------------
 deployment_admin/private/src/deployment_admin.c |  6 ++-
 framework/private/src/framework.c               | 17 ++++---
 framework/private/src/manifest_parser.c         | 53 +++++++++++++-------
 .../private/src/discovery_shmWatcher.c          |  2 +
 .../private/src/endpoint_description.c          | 34 ++++++++-----
 5 files changed, 73 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/74154abc/deployment_admin/private/src/deployment_admin.c
----------------------------------------------------------------------
diff --git a/deployment_admin/private/src/deployment_admin.c b/deployment_admin/private/src/deployment_admin.c
index 1d39477..4a7245b 100644
--- a/deployment_admin/private/src/deployment_admin.c
+++ b/deployment_admin/private/src/deployment_admin.c
@@ -314,7 +314,9 @@ static void *deploymentAdmin_poll(void *deploymentAdmin) {
 					int repoDirLength = strlen(entry) + 5;
 					char repoDir[repoDirLength];
 					snprintf(repoDir, repoDirLength, "%srepo", entry);
-					mkdir(repoDir, S_IRWXU);
+					if( mkdir(repoDir, S_IRWXU) == -1){
+						fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Failed creating directory %s",repoDir);
+					}
 
 					int repoCacheLength = strlen(entry) + strlen(name) + 6;
 					char repoCache[repoCacheLength];
@@ -440,7 +442,7 @@ celix_status_t deploymentAdmin_download(deployment_admin_pt admin, char
* url, c
 		else {
 			*inputFile = strdup("updateXXXXXX");
 		}
-		umask(0000);
+		umask(0011);
         int fd = mkstemp(*inputFile);
         if (fd != -1) {
             FILE *fp = fopen(*inputFile, "wb+");

http://git-wip-us.apache.org/repos/asf/celix/blob/74154abc/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index b81c77a..5f63e74 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -2486,6 +2486,9 @@ static celix_status_t framework_loadBundleLibraries(framework_pt framework,
bund
         if (status == CELIX_SUCCESS) {
             bundle_setHandle(bundle, handle);
         }
+        else if(handle != NULL){
+		fw_closeLibrary(handle);
+        }
     }
 
     framework_logIfError(framework->logger, status, NULL, "Could not load all bundle libraries");
@@ -2527,12 +2530,14 @@ static celix_status_t framework_loadLibraries(framework_pt framework,
char *libr
         char *trimmedLib = utils_stringTrim(lib);
         status = framework_loadLibrary(framework, trimmedLib, archive, &handle);
 
-        if (status == CELIX_SUCCESS) {
-            if (activator != NULL) {
-                if (strcmp(trimmedLib, activator) == 0) {
-                    *activatorHandle = handle;
-                }
-            }
+        if( (status == CELIX_SUCCESS) && (activator != NULL) && (strcmp(trimmedLib,
activator) == 0) ) {
+		*activatorHandle = handle;
+        }
+        else{
+		*activatorHandle = NULL;
+		if(handle != NULL){
+			fw_closeLibrary(handle);
+		}
         }
 
         token = strtok_r(NULL, ",", &last);

http://git-wip-us.apache.org/repos/asf/celix/blob/74154abc/framework/private/src/manifest_parser.c
----------------------------------------------------------------------
diff --git a/framework/private/src/manifest_parser.c b/framework/private/src/manifest_parser.c
index a400a99..1c0735a 100644
--- a/framework/private/src/manifest_parser.c
+++ b/framework/private/src/manifest_parser.c
@@ -174,9 +174,13 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char *
clauseStri
 	linked_list_pt clause = NULL;
 	linked_list_pt pieces = NULL;
 
+	if(linkedList_create(&paths) != CELIX_SUCCESS){
+		return NULL;
+	}
+
 	pieces = manifestParser_parseDelimitedString(clauseString, ";");
 
-	if ((pieces != NULL) && (linkedList_create(&paths) == CELIX_SUCCESS)) {
+	if (pieces != NULL) {
 		int pathCount = 0;
 		int pieceIdx;
 		hash_map_pt dirsMap = NULL;
@@ -216,23 +220,25 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char
* clauseStri
 					break;
 				}
 
-				key = string_ndup(piece, sepPtr - piece);
-				value = strdup(sepPtr+strlen(sep));
-
-				if (value[0] == '"' && value[strlen(value) -1] == '"') {
-					char * oldV = strdup(value);
-					int len = strlen(oldV) - 2;
-					value = (char *) realloc(value, (sizeof(char) * len+1));
-					value[0] = '\0';
-					value = strncpy(value, oldV+1, strlen(oldV) - 2);
-					value[len] = '\0';
-					//check if correct
-					free(oldV);
-				}
-
 				if (strcmp(sep, DIRECTIVE_SEP) == 0) {
 					// Not implemented
-				} else {
+				}
+				else {
+
+					key = string_ndup(piece, sepPtr - piece);
+					value = strdup(sepPtr+strlen(sep));
+
+					if (value[0] == '"' && value[strlen(value) -1] == '"') {
+						char * oldV = strdup(value);
+						int len = strlen(oldV) - 2;
+						value = (char *) realloc(value, (sizeof(char) * len+1));
+						value[0] = '\0';
+						value = strncpy(value, oldV+1, strlen(oldV) - 2);
+						value[len] = '\0';
+						//check if correct
+						free(oldV);
+					}
+
 					attribute_pt attr = NULL;
 					if (hashMap_containsKey(attrsMap, key)) {
 						failure=true;
@@ -251,6 +257,7 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char *
clauseStri
 
 			if(failure){
 				hashMap_destroy(dirsMap,false,false);
+
 				hash_map_iterator_pt attrIter = hashMapIterator_create(attrsMap);
 				while(hashMapIterator_hasNext(attrIter)){
 					hash_map_entry_pt entry = hashMapIterator_nextEntry(attrIter);
@@ -261,15 +268,24 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char
* clauseStri
 				}
 				hashMapIterator_destroy(attrIter);
 				hashMap_destroy(attrsMap,false,false);
+
 				if(key!=NULL){
 					free(key);
 				}
 				if(value!=NULL){
 					free(value);
 				}
+
+				linked_list_iterator_pt piter = linkedListIterator_create(paths,0);
+				while(linkedListIterator_hasNext(piter)){
+					free(linkedListIterator_next(piter));
+				}
+				linkedListIterator_destroy(piter);
 				linkedList_destroy(paths);
+
 				if(clause!=NULL){
 					linkedList_destroy(clause);
+					clause = NULL;
 				}
 			}
 			else{
@@ -289,8 +305,9 @@ static linked_list_pt manifestParser_parseStandardHeaderClause(char *
clauseStri
 		}
 		linkedList_destroy(pieces);
 	}
-
-
+	else{
+		linkedList_destroy(paths);
+	}
 
 	return clause;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/74154abc/remote_services/discovery_shm/private/src/discovery_shmWatcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/src/discovery_shmWatcher.c b/remote_services/discovery_shm/private/src/discovery_shmWatcher.c
index 2123876..ea49c4d 100644
--- a/remote_services/discovery_shm/private/src/discovery_shmWatcher.c
+++ b/remote_services/discovery_shm/private/src/discovery_shmWatcher.c
@@ -219,7 +219,9 @@ celix_status_t discoveryShmWatcher_destroy(discovery_pt discovery) {
     shm_watcher_pt watcher = discovery->watcher;
     char localNodePath[MAX_LOCALNODE_LENGTH];
 
+    celixThreadMutex_lock(&watcher->watcherLock);
     watcher->running = false;
+    celixThreadMutex_unlock(&watcher->watcherLock);
 
     celixThread_join(watcher->watcherThread, NULL);
 

http://git-wip-us.apache.org/repos/asf/celix/blob/74154abc/remote_services/remote_service_admin/private/src/endpoint_description.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/endpoint_description.c b/remote_services/remote_service_admin/private/src/endpoint_description.c
index 1803159..5cf75ce 100644
--- a/remote_services/remote_service_admin/private/src/endpoint_description.c
+++ b/remote_services/remote_service_admin/private/src/endpoint_description.c
@@ -35,27 +35,35 @@
 static celix_status_t endpointDescription_verifyLongProperty(properties_pt properties, char
*propertyName, long *longProperty);
 
 celix_status_t endpointDescription_create(properties_pt properties, endpoint_description_pt
*endpointDescription) {
-	celix_status_t status;
+	celix_status_t status = CELIX_SUCCESS;
 
-    *endpointDescription = malloc(sizeof(**endpointDescription));
+	long serviceId = 0L;
+	status = endpointDescription_verifyLongProperty(properties, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID,
&serviceId);
+	if (status != CELIX_SUCCESS) {
+		return status;
+	}
 
-    long serviceId = 0L;
-    status = endpointDescription_verifyLongProperty(properties, (char *) OSGI_RSA_ENDPOINT_SERVICE_ID,
&serviceId);
-    if (status != CELIX_SUCCESS) {
-    	return status;
-    }
+	endpoint_description_pt ep = calloc(1,sizeof(*ep));
 
-    (*endpointDescription)->properties = properties;
-    (*endpointDescription)->frameworkUUID = properties_get(properties, (char *) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
-    (*endpointDescription)->id = properties_get(properties, (char *) OSGI_RSA_ENDPOINT_ID);
-    (*endpointDescription)->service = properties_get(properties, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
-    (*endpointDescription)->serviceId = serviceId;
+    ep->properties = properties;
+    ep->frameworkUUID = properties_get(properties, (char *) OSGI_RSA_ENDPOINT_FRAMEWORK_UUID);
+    ep->id = properties_get(properties, (char *) OSGI_RSA_ENDPOINT_ID);
+    ep->service = properties_get(properties, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
+    ep->serviceId = serviceId;
 
-    if (!(*endpointDescription)->frameworkUUID || !(*endpointDescription)->id || !(*endpointDescription)->service)
{
+    if (!(ep->frameworkUUID) || !(ep->id) || !(ep->service) ) {
     	fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "ENDPOINT_DESCRIPTION: incomplete description!.");
     	status = CELIX_BUNDLE_EXCEPTION;
     }
 
+    if(status == CELIX_SUCCESS){
+	*endpointDescription = ep;
+    }
+    else{
+	*endpointDescription = NULL;
+	free(ep);
+    }
+
     return status;
 }
 


Mime
View raw message