celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1643879 - in /celix/trunk/remote_services/discovery/private/src: discovery.c endpoint_discovery_poller.c
Date Mon, 08 Dec 2014 18:22:48 GMT
Author: bpetri
Date: Mon Dec  8 18:22:48 2014
New Revision: 1643879

URL: http://svn.apache.org/r1643879
Log:
CELIX-190: fixed memory leak fix :)

Modified:
    celix/trunk/remote_services/discovery/private/src/discovery.c
    celix/trunk/remote_services/discovery/private/src/endpoint_discovery_poller.c

Modified: celix/trunk/remote_services/discovery/private/src/discovery.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery/private/src/discovery.c?rev=1643879&r1=1643878&r2=1643879&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery/private/src/discovery.c (original)
+++ celix/trunk/remote_services/discovery/private/src/discovery.c Mon Dec  8 18:22:48 2014
@@ -201,7 +201,7 @@ celix_status_t discovery_addDiscoveredEn
 	char* endpointId = endpoint->id;
 	bool exists = hashMap_get(discovery->discoveredServices, endpointId) != NULL;
 	if (!exists) {
-		hashMap_put(discovery->discoveredServices, strdup(endpointId), endpoint);
+		hashMap_put(discovery->discoveredServices, endpointId, endpoint);
 	}
 
 	status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);

Modified: celix/trunk/remote_services/discovery/private/src/endpoint_discovery_poller.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery/private/src/endpoint_discovery_poller.c?rev=1643879&r1=1643878&r2=1643879&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery/private/src/endpoint_discovery_poller.c (original)
+++ celix/trunk/remote_services/discovery/private/src/endpoint_discovery_poller.c Mon Dec
 8 18:22:48 2014
@@ -190,7 +190,11 @@ celix_status_t endpointDiscoveryPoller_r
         return CELIX_BUNDLE_EXCEPTION;
     }
 
-	array_list_pt entries = hashMap_remove(poller->entries, url);
+    hash_map_entry_pt endpointEntry = hashMap_removeEntryForKey(poller->entries, url);
+
+    free(hashMapEntry_getKey(endpointEntry));
+    array_list_pt entries = hashMapEntry_getValue(endpointEntry);
+
 	for (int i = 0; i < arrayList_size(entries); i++) {
 		endpoint_description_pt endpoint = arrayList_get(entries, i);
 
@@ -234,23 +238,31 @@ static void *endpointDiscoveryPoller_pol
 			}
 
 			for (int i = arrayList_size(currentEndpoints); i > 0  ; i--) {
-				endpoint_description_pt endpoint = arrayList_remove(currentEndpoints, 0);
+				endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i-1);
 				if (!arrayList_contains(updatedEndpoints, endpoint)) {
 					status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
+					arrayList_remove(currentEndpoints, i-1);
+					endpointDescription_destroy(endpoint);
+				}
+			}
+
+			for (int i = arrayList_size(updatedEndpoints); i > 0  ; i--) {
+				endpoint_description_pt endpoint = arrayList_remove(updatedEndpoints, 0);
+
+				if (!arrayList_contains(currentEndpoints, endpoint)) {
+					arrayList_add(currentEndpoints, endpoint);
+					status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
+				}
+				else {
+					endpointDescription_destroy(endpoint);
+
 				}
-				endpointDescription_destroy(endpoint);
 			}
 
 			if (updatedEndpoints) {
-				arrayList_addAll(currentEndpoints, updatedEndpoints);
 				arrayList_destroy(updatedEndpoints);
 			}
 
-			for (int i = 0; i < arrayList_size(currentEndpoints); i++) {
-				endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i);
-
-				status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
-			}
 		}
 
 		hashMapIterator_destroy(iterator);



Mime
View raw message