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 <erjanalt...@gmail.com> Authored: Thu Feb 8 19:05:30 2018 +0100 Committer: Erjan Altena <erjanalt...@gmail.com> 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(&url, "http://%s:%d/v2/keys/%s?wait=true&recursive=true&waitIndex=%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, &action, &prevValue, &value, &rkey, &modifiedIndex); 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, &action, &prevValue, &value, &rkey, &modifiedIndex); 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", &value, &index); + free(value); pthread_t waitThread; index++; pthread_create(&waitThread, NULL, waitForChange, &index); @@ -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 &customizer); 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 = shellCommand; + bundleContext_registerService(context, OSGI_SHELL_COMMAND_SERVICE_NAME, &activator->admin->shellCmdService, shellProps, &activator->admin->shellCmdReg); + } else { serviceTrackerCustomizer_destroy(customizer); pubsubAdmin_destroy(activator->admin); } @@ -108,13 +116,6 @@ 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, &activator->admin->shellCmdService, shellProps, &activator->admin->shellCmdReg); } return status; }