You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2014/08/30 20:27:51 UTC

svn commit: r1621504 - in /celix/trunk/framework/private: include/attribute.h src/attribute.c src/bundle_archive.c src/capability.c src/framework.c src/manifest.c src/module.c src/requirement.c src/version_range.c

Author: abroekhuis
Date: Sat Aug 30 18:27:50 2014
New Revision: 1621504

URL: http://svn.apache.org/r1621504
Log:
Fixed several memory leaks.

Modified:
    celix/trunk/framework/private/include/attribute.h
    celix/trunk/framework/private/src/attribute.c
    celix/trunk/framework/private/src/bundle_archive.c
    celix/trunk/framework/private/src/capability.c
    celix/trunk/framework/private/src/framework.c
    celix/trunk/framework/private/src/manifest.c
    celix/trunk/framework/private/src/module.c
    celix/trunk/framework/private/src/requirement.c
    celix/trunk/framework/private/src/version_range.c

Modified: celix/trunk/framework/private/include/attribute.h
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/include/attribute.h?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/include/attribute.h (original)
+++ celix/trunk/framework/private/include/attribute.h Sat Aug 30 18:27:50 2014
@@ -31,6 +31,7 @@
 typedef struct attribute *attribute_pt;
 
 celix_status_t attribute_create(char * key, char * value, attribute_pt *attribute);
+celix_status_t attribute_destroy(attribute_pt attribute);
 
 celix_status_t attribute_getKey(attribute_pt attribute, char **key);
 celix_status_t attribute_getValue(attribute_pt attribute, char **value);

Modified: celix/trunk/framework/private/src/attribute.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/attribute.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/attribute.c (original)
+++ celix/trunk/framework/private/src/attribute.c Sat Aug 30 18:27:50 2014
@@ -53,6 +53,13 @@ celix_status_t attribute_create(char * k
 	return status;
 }
 
+celix_status_t attribute_destroy(attribute_pt attribute) {
+    free(attribute->key);
+    free(attribute->value);
+    free(attribute);
+    return CELIX_SUCCESS;
+}
+
 celix_status_t attribute_getKey(attribute_pt attribute, char **key) {
 	*key = attribute->key;
 	return CELIX_SUCCESS;

Modified: celix/trunk/framework/private/src/bundle_archive.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/bundle_archive.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/bundle_archive.c (original)
+++ celix/trunk/framework/private/src/bundle_archive.c Sat Aug 30 18:27:50 2014
@@ -113,7 +113,7 @@ celix_status_t bundleArchive_create(fram
 			status = linkedList_create(&archive->revisions);
 			if (status == CELIX_SUCCESS) {
                 archive->id = id;
-                archive->location = location;
+                archive->location = strdup(location);
                 archive->archiveRootDir = NULL;
                 archive->archiveRoot = archiveRoot;
                 archive->refreshCount = -1;

Modified: celix/trunk/framework/private/src/capability.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/capability.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/capability.c (original)
+++ celix/trunk/framework/private/src/capability.c Sat Aug 30 18:27:50 2014
@@ -67,6 +67,7 @@ celix_status_t capability_destroy(capabi
 	while (hashMapIterator_hasNext(attrIter)) {
 		attribute_pt attr = hashMapIterator_nextValue(attrIter);
 		hashMapIterator_remove(attrIter);
+		attribute_destroy(attr);
 	}
 	hashMapIterator_destroy(attrIter);
 	hashMap_destroy(capability->attributes, false, false);
@@ -79,6 +80,8 @@ celix_status_t capability_destroy(capabi
 	version_destroy(capability->version);
 	capability->version = NULL;
 
+	free(capability);
+
 	return CELIX_SUCCESS;
 }
 

Modified: celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/framework.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/framework.c (original)
+++ celix/trunk/framework/private/src/framework.c Sat Aug 30 18:27:50 2014
@@ -233,19 +233,6 @@ celix_status_t framework_destroy(framewo
 		char *location = (char *) hashMapEntry_getKey(entry);
 		bundle_archive_pt archive = NULL;
 
-		// for each installed bundle, clean up memory
-		module_pt mod = NULL;
-		bundle_getCurrentModule(bundle, &mod);
-		wires = module_getWires(mod);
-		if (wires != NULL) {
-			linked_list_iterator_pt iter = linkedListIterator_create(wires, 0);
-			while (linkedListIterator_hasNext(iter)) {
-				wire_pt wire = (wire_pt) linkedListIterator_next(iter);
-				linkedListIterator_remove(iter);
-			}
-			linkedListIterator_destroy(iter);
-		}
-
 		if (bundle_getArchive(bundle, &archive) == CELIX_SUCCESS) {
 			bundleArchive_destroy(archive);
 		}
@@ -2098,6 +2085,7 @@ celix_status_t fw_fireFrameworkEvent(fra
 		request->listeners = framework->frameworkListeners;
 		request->type = FRAMEWORK_EVENT_TYPE;
 		request->errorCode = errorCode;
+		request->error = "";
 
 		if (errorCode != CELIX_SUCCESS) {
 		    char message[256];

Modified: celix/trunk/framework/private/src/manifest.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/manifest.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/manifest.c (original)
+++ celix/trunk/framework/private/src/manifest.c Sat Aug 30 18:27:50 2014
@@ -224,7 +224,7 @@ celix_status_t manifest_readAttributes(m
 
 			// Line continued
 			if (name == NULL) {
-				free(buf);
+			    buf[0] = '\0';
 				printf("MANIFEST: No continued line expected\n");
 				return CELIX_FILE_IO_EXCEPTION;
 			}

Modified: celix/trunk/framework/private/src/module.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/module.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/module.c (original)
+++ celix/trunk/framework/private/src/module.c Sat Aug 30 18:27:50 2014
@@ -112,8 +112,6 @@ module_pt module_createFrameworkModule(b
 void module_destroy(module_pt module) {
 	arrayList_destroy(module->dependentImporters);
 
-	linkedList_destroy(module->capabilities);
-	linkedList_destroy(module->requirements);
 	version_destroy(module->version);
 
 	if (module->wires != NULL) {
@@ -127,6 +125,28 @@ void module_destroy(module_pt module) {
         linkedList_destroy(module->wires);
 	}
 
+	if (module->requirements != NULL) {
+	    linked_list_iterator_pt iter = linkedListIterator_create(module->requirements, 0);
+        while (linkedListIterator_hasNext(iter)) {
+            requirement_pt next = linkedListIterator_next(iter);
+            linkedListIterator_remove(iter);
+            requirement_destroy(next);
+        }
+        linkedListIterator_destroy(iter);
+        linkedList_destroy(module->requirements);
+	}
+
+	if (module->capabilities != NULL) {
+	    linked_list_iterator_pt iter = linkedListIterator_create(module->capabilities, 0);
+        while (linkedListIterator_hasNext(iter)) {
+            capability_pt next = linkedListIterator_next(iter);
+            linkedListIterator_remove(iter);
+            capability_destroy(next);
+        }
+        linkedListIterator_destroy(iter);
+        linkedList_destroy(module->capabilities);
+    }
+
 	module->headerMap = NULL;
 
 	free(module->id);

Modified: celix/trunk/framework/private/src/requirement.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/requirement.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/requirement.c (original)
+++ celix/trunk/framework/private/src/requirement.c Sat Aug 30 18:27:50 2014
@@ -70,6 +70,7 @@ celix_status_t requirement_destroy(requi
 	while (hashMapIterator_hasNext(attrIter)) {
 		attribute_pt attr = hashMapIterator_nextValue(attrIter);
 		hashMapIterator_remove(attrIter);
+		attribute_destroy(attr);
 	}
 	hashMapIterator_destroy(attrIter);
 	hashMap_destroy(requirement->attributes, false, false);
@@ -77,8 +78,12 @@ celix_status_t requirement_destroy(requi
 
 	requirement->attributes = NULL;
 	requirement->directives = NULL;
+
+	versionRange_destroy(requirement->versionRange);
 	requirement->versionRange = NULL;
 
+	free(requirement);
+
 	return CELIX_SUCCESS;
 }
 

Modified: celix/trunk/framework/private/src/version_range.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/version_range.c?rev=1621504&r1=1621503&r2=1621504&view=diff
==============================================================================
--- celix/trunk/framework/private/src/version_range.c (original)
+++ celix/trunk/framework/private/src/version_range.c Sat Aug 30 18:27:50 2014
@@ -49,10 +49,20 @@ celix_status_t versionRange_createVersio
 }
 
 celix_status_t versionRange_destroy(version_range_pt range) {
+    if (range->high != NULL) {
+        version_destroy(range->high);
+    }
+    if (range->low != NULL) {
+        version_destroy(range->low);
+    }
+
 	range->high = NULL;
 	range->isHighInclusive = false;
 	range->low = NULL;
 	range->isLowInclusive = false;
+
+	free(range);
+
 	return CELIX_SUCCESS;
 }