celix git commit: Fixed memory leaks reported by coverity

2018-02-08 Thread erjanaltena
Repository: celix
Updated Branches:
  refs/heads/develop 7b3d1a8e5 -> af26af6b7


Fixed memory leaks reported by coverity


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

Branch: refs/heads/develop
Commit: af26af6b71513a1d808b88e617beced679ddad81
Parents: 7b3d1a8
Author: Erjan Altena 
Authored: Thu Feb 8 19:05:30 2018 +0100
Committer: Erjan Altena 
Committed: Thu Feb 8 19:05:30 2018 +0100

--
 etcdlib/src/etcd.c  |  8 +---
 etcdlib/test/etcdlib_test.c |  7 +++
 pubsub/pubsub_admin_zmq/src/psa_activator.c | 17 +
 3 files changed, 17 insertions(+), 15 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/celix/blob/af26af6b/etcdlib/src/etcd.c
--
diff --git a/etcdlib/src/etcd.c b/etcdlib/src/etcd.c
index 861b07a..0c9d615 100644
--- a/etcdlib/src/etcd.c
+++ b/etcdlib/src/etcd.c
@@ -374,9 +374,6 @@ int etcd_watch(const char* key, long long index, char** 
action, char** prevValue
 reply.header = NULL; /* will be grown as needed by the realloc above */
 reply.headerSize = 0; /* no data at this point */
 
-reply.header = malloc(1); /* will be grown as needed by the realloc above 
*/
-reply.headerSize = 0; /* no data at this point */
-
if (index != 0)
asprintf(, 
"http://%s:%d/v2/keys/%s?wait=true=true=%lld;, etcd_server, 
etcd_port, key, index);
else
@@ -431,9 +428,7 @@ int etcd_watch(const char* key, long long index, char** 
action, char** prevValue
 
}
 
-   if (reply.memory) {
-   free(reply.memory);
-   }
+   free(reply.memory);
 
return retVal;
 }
@@ -475,7 +470,6 @@ int etcd_del(const char* key) {
}
 
free(reply.memory);
-   free(reply.header);
 
return retVal;
 }

http://git-wip-us.apache.org/repos/asf/celix/blob/af26af6b/etcdlib/test/etcdlib_test.c
--
diff --git a/etcdlib/test/etcdlib_test.c b/etcdlib/test/etcdlib_test.c
index 7c2d573..afd0e74 100644
--- a/etcdlib/test/etcdlib_test.c
+++ b/etcdlib/test/etcdlib_test.c
@@ -40,6 +40,7 @@ int simplewritetest() {
 printf("etcdlib test error: expected testvalue got %s\n", value);
 res = -1;
 }
+free(value);
 return res;
 }
 
@@ -53,6 +54,10 @@ void* waitForChange(void*arg) {
 printf("Watching for index %d\n", *idx);
 etcd_watch("hier/ar", *idx, , , , , 
);
 printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
+free (action);
+free(prevValue);
+free(rkey);
+free(value);
 *idx = modifiedIndex+1;
 etcd_watch("hier/ar", *idx, , , , , 
);
 printf(" New value from watch : [%s]%s => %s\n", rkey, prevValue, value);
@@ -70,6 +75,7 @@ int waitforchangetest() {
 
 int index;
 etcd_get("hier/ar/chi/cal", , );
+free(value);
 pthread_t waitThread;
 index++;
 pthread_create(, NULL, waitForChange, );
@@ -83,6 +89,7 @@ int waitforchangetest() {
 printf("etcdtest::waitforchange1 expected testvalue3, got %s\n", 
(char*)resVal);
 res = -1;
 }
+free(resVal);
 return res;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/af26af6b/pubsub/pubsub_admin_zmq/src/psa_activator.c
--
diff --git a/pubsub/pubsub_admin_zmq/src/psa_activator.c 
b/pubsub/pubsub_admin_zmq/src/psa_activator.c
index f754cd1..687e909 100644
--- a/pubsub/pubsub_admin_zmq/src/psa_activator.c
+++ b/pubsub/pubsub_admin_zmq/src/psa_activator.c
@@ -99,7 +99,15 @@ celix_status_t bundleActivator_create(bundle_context_pt 
context, void **userData
);
if(status == CELIX_SUCCESS){
status = serviceTracker_create(context, 
PUBSUB_SERIALIZER_SERVICE, customizer, &(activator->serializerTracker));
-   if(status != CELIX_SUCCESS){
+if (status == CELIX_SUCCESS) {
+properties_pt shellProps = properties_create();
+properties_set(shellProps, OSGI_SHELL_COMMAND_NAME, 
"psa_zmq_info");
+properties_set(shellProps, OSGI_SHELL_COMMAND_USAGE, 
"psa_zmq_info");
+properties_set(shellProps, OSGI_SHELL_COMMAND_DESCRIPTION, 
"psa_zmq_info: Overview of PubSub ZMQ Admin");
+activator->admin->shellCmdService.handle = activator;
+activator->admin->shellCmdService.executeCommand = 

[1/2] celix git commit: Discovery subscriber failed reading ETCD when started without existing publisher

2018-02-08 Thread erjanaltena
Repository: celix
Updated Branches:
  refs/heads/develop 24bad0e41 -> 490811d2c


Discovery subscriber failed reading ETCD when started without existing publisher


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

Branch: refs/heads/develop
Commit: a0d4621d9056d208695cb5d97788153ddfa1b3bc
Parents: f988011
Author: Erjan Altena 
Authored: Thu Feb 8 11:32:28 2018 +0100
Committer: Erjan Altena 
Committed: Thu Feb 8 11:32:28 2018 +0100

--
 etcdlib/src/etcd.c  | 14 +-
 pubsub/pubsub_admin_zmq/src/psa_activator.c | 14 +++---
 2 files changed, 20 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/celix/blob/a0d4621d/etcdlib/src/etcd.c
--
diff --git a/etcdlib/src/etcd.c b/etcdlib/src/etcd.c
index f75fa03..cb5c0ff 100644
--- a/etcdlib/src/etcd.c
+++ b/etcdlib/src/etcd.c
@@ -33,6 +33,7 @@
 #define ETCD_JSON_VALUE "value"
 #define ETCD_JSON_DIR   "dir"
 #define ETCD_JSON_MODIFIEDINDEX "modifiedIndex"
+#define ETCD_JSON_INDEX "index"
 
 #define MAX_OVERHEAD_LENGTH   64
 #define DEFAULT_CURL_TIMEOUT  10
@@ -198,7 +199,6 @@ int etcd_get_directory(const char* directory, 
etcd_key_value_callback callback,
 
res = performRequest(url, GET, WriteMemoryCallback, NULL, (void*) 
);
free(url);
-
if (res == CURLE_OK) {
js_root = json_loads(reply.memory, 0, );
if (js_root != NULL) {
@@ -210,6 +210,18 @@ int etcd_get_directory(const char* directory, 
etcd_key_value_callback callback,
if (js_rootnode != NULL) {
*modifiedIndex = 0;
retVal = etcd_get_recursive_values(js_rootnode, 
callback, arg, (json_int_t*)modifiedIndex);
+   } else {
+   // Error occured, retrieve the index of ETCD from the 
error code
+   js_rootnode = json_object_get(js_root, ETCD_JSON_INDEX);
+   if(js_rootnode) {
+   json_int_t index = 
json_integer_value(js_rootnode);
+   *modifiedIndex = index;
+
+   } else {
+   fprintf(stderr, "[ETCDLIB] Error: index not 
found in error %s\n", reply.memory);
+
+   }
+
}
if (js_root != NULL) {
json_decref(js_root);

http://git-wip-us.apache.org/repos/asf/celix/blob/a0d4621d/pubsub/pubsub_admin_zmq/src/psa_activator.c
--
diff --git a/pubsub/pubsub_admin_zmq/src/psa_activator.c 
b/pubsub/pubsub_admin_zmq/src/psa_activator.c
index 73c45fa..f754cd1 100644
--- a/pubsub/pubsub_admin_zmq/src/psa_activator.c
+++ b/pubsub/pubsub_admin_zmq/src/psa_activator.c
@@ -108,14 +108,14 @@ celix_status_t bundleActivator_create(bundle_context_pt 
context, void **userData
pubsubAdmin_destroy(activator->admin);
}
}
+   properties_pt shellProps = properties_create();
+   properties_set(shellProps, OSGI_SHELL_COMMAND_NAME, 
"psa_zmq_info");
+   properties_set(shellProps, OSGI_SHELL_COMMAND_USAGE, 
"psa_zmq_info");
+   properties_set(shellProps, OSGI_SHELL_COMMAND_DESCRIPTION, 
"psa_zmq_info: Overview of PubSub ZMQ Admin");
+   activator->admin->shellCmdService.handle = activator;
+   activator->admin->shellCmdService.executeCommand = shellCommand;
+   bundleContext_registerService(context, 
OSGI_SHELL_COMMAND_SERVICE_NAME, >admin->shellCmdService, 
shellProps, >admin->shellCmdReg);
}
-properties_pt shellProps = properties_create();
-properties_set(shellProps, OSGI_SHELL_COMMAND_NAME, "psa_zmq_info");
-properties_set(shellProps, OSGI_SHELL_COMMAND_USAGE, "psa_zmq_info");
-properties_set(shellProps, OSGI_SHELL_COMMAND_DESCRIPTION, "psa_zmq_info: 
Overview of PubSub ZMQ Admin");
-activator->admin->shellCmdService.handle = activator;
-activator->admin->shellCmdService.executeCommand = shellCommand;
-bundleContext_registerService(context, OSGI_SHELL_COMMAND_SERVICE_NAME, 
>admin->shellCmdService, shellProps, >admin->shellCmdReg);
return status;
 }
 



[2/2] celix git commit: Merge branch 'develop' of https://github.com/apache/celix into develop

2018-02-08 Thread erjanaltena
Merge branch 'develop' of https://github.com/apache/celix into develop


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

Branch: refs/heads/develop
Commit: 490811d2c41cd5c375e25dc58dcf2f4ef67e7d7a
Parents: a0d4621 24bad0e
Author: Erjan Altena 
Authored: Thu Feb 8 11:36:22 2018 +0100
Committer: Erjan Altena 
Committed: Thu Feb 8 11:36:22 2018 +0100

--
 pubsub/pubsub_admin_udp_mc/src/topic_publication.c | 2 ++
 remote_services/remote_services_api/CMakeLists.txt | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
--




celix git commit: etcd_get_directory retrieves the index from the HTTP header instead of the last modified index in the content

2018-02-08 Thread erjanaltena
Repository: celix
Updated Branches:
  refs/heads/develop 490811d2c -> 7b3d1a8e5


etcd_get_directory retrieves the index from the HTTP header instead of the last 
modified index in the content


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

Branch: refs/heads/develop
Commit: 7b3d1a8e5ddca7b4f72897c2be8ff26e55e50a5d
Parents: 490811d
Author: Erjan Altena 
Authored: Thu Feb 8 14:20:54 2018 +0100
Committer: Erjan Altena 
Committed: Thu Feb 8 14:20:54 2018 +0100

--
 etcdlib/src/etcd.c | 102 
 1 file changed, 78 insertions(+), 24 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/celix/blob/7b3d1a8e/etcdlib/src/etcd.c
--
diff --git a/etcdlib/src/etcd.c b/etcdlib/src/etcd.c
index cb5c0ff..861b07a 100644
--- a/etcdlib/src/etcd.c
+++ b/etcdlib/src/etcd.c
@@ -35,6 +35,8 @@
 #define ETCD_JSON_MODIFIEDINDEX "modifiedIndex"
 #define ETCD_JSON_INDEX "index"
 
+#define ETCD_HEADER_INDEX   "X-Etcd-Index: "
+
 #define MAX_OVERHEAD_LENGTH   64
 #define DEFAULT_CURL_TIMEOUT  10
 #define DEFAULT_CURL_CONECTTIMEOUT10
@@ -48,14 +50,16 @@ static int etcd_port = 0;
 
 struct MemoryStruct {
char *memory;
-   size_t size;
+   char *header;
+   size_t memorySize;
+size_t headerSize;
 };
 
 
 /**
  * Static function declarations
  */
-static int performRequest(char* url, request_t request, void* callback, void* 
reqData, void* repData);
+static int performRequest(char* url, request_t request, void* reqData, void* 
repData);
 static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, 
void *userp);
 /**
  * External function definition
@@ -92,12 +96,14 @@ int etcd_get(const char* key, char** value, int* 
modifiedIndex) {
struct MemoryStruct reply;
 
reply.memory = malloc(1); /* will be grown as needed by the realloc 
above */
-   reply.size = 0; /* no data at this point */
+   reply.memorySize = 0; /* no data at this point */
+reply.header = NULL; /* will be grown as needed by the realloc above */
+reply.headerSize = 0; /* no data at this point */
 
int retVal = -1;
char *url;
asprintf(, "http://%s:%d/v2/keys/%s;, etcd_server, etcd_port, key);
-   res = performRequest(url, GET, WriteMemoryCallback, NULL, (void*) 
);
+   res = performRequest(url, GET, NULL, (void*) );
free(url);
 
if (res == CURLE_OK) {
@@ -178,6 +184,17 @@ static int etcd_get_recursive_values(json_t* js_root, 
etcd_key_value_callback ca
return (*mod_index > 0 ? 0 : 1);
 }
 
+static long long etcd_get_current_index(const char* headerData) {
+long long index = -1;
+char * indexStr = strstr(headerData, ETCD_HEADER_INDEX);
+indexStr += strlen(ETCD_HEADER_INDEX);
+
+if (sscanf(indexStr, "%lld\n",) == 1) {
+} else {
+index = -1;
+}
+return index;
+}
 /**
  * etcd_get_directory
  */
@@ -190,14 +207,16 @@ int etcd_get_directory(const char* directory, 
etcd_key_value_callback callback,
struct MemoryStruct reply;
 
reply.memory = malloc(1); /* will be grown as needed by the realloc 
above */
-   reply.size = 0; /* no data at this point */
+   reply.memorySize = 0; /* no data at this point */
+reply.header = malloc(1); /* will be grown as needed by the realloc above 
*/
+reply.headerSize = 0; /* no data at this point */
 
int retVal = 0;
char *url;
 
asprintf(, "http://%s:%d/v2/keys/%s?recursive=true;, etcd_server, 
etcd_port, directory);
 
-   res = performRequest(url, GET, WriteMemoryCallback, NULL, (void*) 
);
+   res = performRequest(url, GET, NULL, (void*) );
free(url);
if (res == CURLE_OK) {
js_root = json_loads(reply.memory, 0, );
@@ -210,6 +229,10 @@ int etcd_get_directory(const char* directory, 
etcd_key_value_callback callback,
if (js_rootnode != NULL) {
*modifiedIndex = 0;
retVal = etcd_get_recursive_values(js_rootnode, 
callback, arg, (json_int_t*)modifiedIndex);
+long long indexFromHeader = etcd_get_current_index(reply.header);
+if (indexFromHeader > *modifiedIndex) {
+  *modifiedIndex = indexFromHeader;
+}
} else {
// Error occured, retrieve the index of ETCD from the 
error code
js_rootnode = json_object_get(js_root, ETCD_JSON_INDEX);
@@ -228,9 +251,8 @@ int