celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1643059 - in /celix/trunk/remote_services: discovery/private/src/endpoint_discovery_server.c remote_service_admin_http/private/src/remote_service_admin_impl.c
Date Mon, 15 Dec 2014 17:12:15 GMT
Author: bpetri
Date: Wed Dec  3 06:25:00 2014
New Revision: 1643059

URL: http://svn.apache.org/r1643059
Log:
CELIX-190: fixed memory leak in getIpAdress handling

Modified:
    celix/trunk/remote_services/discovery/private/src/endpoint_discovery_server.c
    celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c

Modified: celix/trunk/remote_services/discovery/private/src/endpoint_discovery_server.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/discovery/private/src/endpoint_discovery_server.c?rev=1643059&r1=1643058&r2=1643059&view=diff
==============================================================================
--- celix/trunk/remote_services/discovery/private/src/endpoint_discovery_server.c (original)
+++ celix/trunk/remote_services/discovery/private/src/endpoint_discovery_server.c Wed Dec
 3 06:25:00 2014
@@ -75,6 +75,7 @@ celix_status_t endpointDiscoveryServer_c
 
 	char *port = 0;
 	char *ip = NULL;
+	char *detectedIp = NULL;
 	char *path = NULL;
 
 	*server = malloc(sizeof(struct endpoint_discovery_server));
@@ -99,13 +100,15 @@ celix_status_t endpointDiscoveryServer_c
 		char *interface = NULL;
 
 		bundleContext_getProperty(context, DISCOVERY_SERVER_INTERFACE, &interface);
-		if ((interface != NULL) && (endpointDiscoveryServer_getIpAdress(interface, &ip)
!= CELIX_SUCCESS)) {
+		if ((interface != NULL) && (endpointDiscoveryServer_getIpAdress(interface, &detectedIp)
!= CELIX_SUCCESS)) {
 			logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "Could not retrieve IP
adress for interface %s", interface);
 		}
 
-		if (ip == NULL) {
-			endpointDiscoveryServer_getIpAdress(NULL, &ip);
+		if (detectedIp == NULL) {
+			endpointDiscoveryServer_getIpAdress(NULL, &detectedIp);
 		}
+
+		ip = detectedIp;
 	}
 
 	if (ip != NULL) {
@@ -117,6 +120,10 @@ celix_status_t endpointDiscoveryServer_c
 		(*server)->ip = (char*) DEFAULT_SERVER_IP;
 	}
 
+	if (detectedIp != NULL) {
+		free(detectedIp);
+	}
+
 	bundleContext_getProperty(context, DISCOVERY_SERVER_PORT, &port);
 	if (port == NULL) {
 		port = DEFAULT_SERVER_PORT;

Modified: celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c?rev=1643059&r1=1643058&r2=1643059&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
(original)
+++ celix/trunk/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
Wed Dec  3 06:25:00 2014
@@ -105,6 +105,7 @@ celix_status_t remoteServiceAdmin_create
 		unsigned int port_counter = 0;
 		char *port = NULL;
 		char *ip = NULL;
+		char *detectedIp = NULL;
 
 		(*admin)->pool = pool;
 		(*admin)->context = context;
@@ -125,13 +126,15 @@ celix_status_t remoteServiceAdmin_create
 			char *interface = NULL;
 
 			bundleContext_getProperty(context, "RSA_INTERFACE", &interface);
-			if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &ip)
!= CELIX_SUCCESS)) {
+			if ((interface != NULL) && (remoteServiceAdmin_getIpAdress(interface, &detectedIp)
!= CELIX_SUCCESS)) {
 				logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: Could not retrieve
IP adress for interface %s", interface);
 			}
 
 			if (ip == NULL) {
-				remoteServiceAdmin_getIpAdress(NULL, &ip);
+				remoteServiceAdmin_getIpAdress(NULL, &detectedIp);
 			}
+
+			ip = detectedIp;
 		}
 
 		if (ip != NULL) {
@@ -143,6 +146,10 @@ celix_status_t remoteServiceAdmin_create
 			(*admin)->ip = (char*) DEFAULT_IP;
 		}
 
+		if (detectedIp != NULL) {
+			free(detectedIp);
+		}
+
 		// Prepare callbacks structure. We have only one callback, the rest are NULL.
 		struct mg_callbacks callbacks;
 		memset(&callbacks, 0, sizeof(callbacks));



Mime
View raw message