You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2016/04/29 18:58:14 UTC
[3/3] celix git commit: CELIX-357: Fixes coverity warnings. Medium
priority
CELIX-357: Fixes coverity warnings. Medium priority
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/137fdf5c
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/137fdf5c
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/137fdf5c
Branch: refs/heads/develop
Commit: 137fdf5c3cf86c3357c1f0cac6163ded561df297
Parents: 6990fce
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Fri Apr 29 18:59:07 2016 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Fri Apr 29 18:59:07 2016 +0200
----------------------------------------------------------------------
.../private/src/dm_activator_base.c | 4 +
.../private/src/dm_component_impl.c | 55 +-
.../private/src/dm_service_dependency.c | 6 +-
.../private/src/dm_shell_activator.c | 23 +-
.../private/src/dm_shell_list_command.c | 8 +-
deployment_admin/private/src/deployment_admin.c | 8 +-
.../device_access/private/src/device_manager.c | 4 +-
.../driver_locator/private/src/activator.c | 35 +-
dfi/private/src/dyn_function.c | 13 +-
dfi/private/src/dyn_interface.c | 13 +-
dfi/private/src/dyn_message.c | 10 +-
dfi/private/src/dyn_type.c | 7 +-
dfi/private/src/json_rpc.c | 571 ++++++++++---------
dfi/private/src/json_serializer.c | 10 +-
.../test/avro_descriptor_translator_tests.cpp | 1 +
dfi/private/test/dyn_closure_tests.cpp | 1 +
dfi/private/test/dyn_function_tests.cpp | 1 +
dfi/private/test/dyn_message_tests.cpp | 1 +
dfi/private/test/dyn_type_tests.cpp | 1 +
dfi/private/test/json_rpc_tests.cpp | 9 +-
dfi/private/test/json_serializer_tests.cpp | 1 +
examples/embedding/private/src/main.c | 67 ++-
.../private/src/benchmark_runner_activator.c | 9 +-
.../private/src/mutex_benchmark.c | 2 +
examples/mongoose/private/src/mongoose.c | 18 +-
.../private/src/listener_example.c | 2 +-
.../private/src/activator.c | 2 +-
framework/private/mock/celix_log_mock.c | 2 +
framework/private/src/bundle_archive.c | 4 +-
framework/private/src/bundle_cache.c | 9 +-
framework/private/src/celix_launcher.c | 208 +++----
framework/private/src/celix_log.c | 4 +
framework/private/src/framework.c | 126 ++--
framework/private/src/resolver.c | 12 +-
framework/private/test/bundle_cache_test.cpp | 25 +-
framework/private/test/bundle_test.cpp | 2 +-
log_service/private/src/log.c | 10 +-
.../private/src/log_reader_service_impl.c | 2 +-
log_service/private/src/log_service_impl.c | 8 +-
log_service/public/src/log_helper.c | 27 +-
.../private/src/endpoint_descriptor_reader.c | 5 +-
.../private/src/endpoint_discovery_poller.c | 24 +-
.../discovery_shm/private/src/discovery_shm.c | 11 +-
.../calculator_shell/private/src/add_command.c | 45 +-
.../calculator_shell/private/src/sqrt_command.c | 31 +-
.../calculator_shell/private/src/sub_command.c | 13 +-
.../rsa/private/src/import_registration_dfi.c | 6 +-
.../rsa/private/src/remote_service_admin_dfi.c | 14 +-
.../private/src/remote_service_admin_impl.c | 20 +-
.../private/src/remote_service_admin_impl.c | 4 +-
.../private/src/topology_manager.c | 34 +-
remote_services/utils/private/src/civetweb.c | 14 +-
remote_shell/private/src/remote_shell.c | 2 +-
remote_shell/private/src/shell_mediator.c | 2 +-
shell/private/src/shell.c | 2 +-
utils/private/src/thpool.c | 4 +-
utils/private/test/celix_threads_test.cpp | 13 +-
57 files changed, 818 insertions(+), 747 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dependency_manager/private/src/dm_activator_base.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_activator_base.c b/dependency_manager/private/src/dm_activator_base.c
index a7e6500..cbd1762 100644
--- a/dependency_manager/private/src/dm_activator_base.c
+++ b/dependency_manager/private/src/dm_activator_base.c
@@ -112,6 +112,10 @@ celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt contex
celix_status_t status = CELIX_SUCCESS;
dependency_activator_base_pt dependency_activator = (dependency_activator_base_pt) userData;
+ if(dependency_activator==NULL){
+ return CELIX_ILLEGAL_ARGUMENT;
+ }
+
status = dm_destroy(dependency_activator->userData, dependency_activator->context,
dependency_activator->manager);
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dependency_manager/private/src/dm_component_impl.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_component_impl.c b/dependency_manager/private/src/dm_component_impl.c
index 0d9745e..ef46811 100644
--- a/dependency_manager/private/src/dm_component_impl.c
+++ b/dependency_manager/private/src/dm_component_impl.c
@@ -503,6 +503,7 @@ celix_status_t component_handleChanged(dm_component_pt component, dm_service_dep
array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
int index = arrayList_indexOf(events, event);
if (index < 0) {
+ pthread_mutex_unlock(&component->mutex);
status = CELIX_BUNDLE_EXCEPTION;
} else {
dm_event_pt old = arrayList_remove(events, (unsigned int) index);
@@ -556,6 +557,7 @@ celix_status_t component_handleRemoved(dm_component_pt component, dm_service_dep
pthread_mutex_lock(&component->mutex);
int index = arrayList_indexOf(events, event);
if (index < 0) {
+ pthread_mutex_unlock(&component->mutex);
status = CELIX_BUNDLE_EXCEPTION;
} else {
dm_event_pt old = arrayList_remove(events, (unsigned int) index);
@@ -608,6 +610,7 @@ celix_status_t component_handleSwapped(dm_component_pt component, dm_service_dep
array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
int index = arrayList_indexOf(events, event);
if (index < 0) {
+ pthread_mutex_unlock(&component->mutex);
status = CELIX_BUNDLE_EXCEPTION;
} else {
dm_event_pt old = arrayList_remove(events, (unsigned int) index);
@@ -1340,37 +1343,35 @@ celix_status_t component_getComponentInfo(dm_component_pt component, dm_componen
dm_component_info_pt info = NULL;
info = calloc(1, sizeof(*info));
+ if(info==NULL){
+ return CELIX_ENOMEM;
+ }
- if (info != NULL) {
- arrayList_create(&info->dependency_list);
- component_getInterfaces(component, &info->interfaces);
- info->active = false;
- memcpy(info->id, component->id, DM_COMPONENT_MAX_ID_LENGTH);
- memcpy(info->name, component->name, DM_COMPONENT_MAX_NAME_LENGTH);
+ arrayList_create(&info->dependency_list);
+ component_getInterfaces(component, &info->interfaces);
+ info->active = false;
+ memcpy(info->id, component->id, DM_COMPONENT_MAX_ID_LENGTH);
+ memcpy(info->name, component->name, DM_COMPONENT_MAX_NAME_LENGTH);
- switch (component->state) {
- case DM_CMP_STATE_INACTIVE :
- info->state = strdup("INACTIVE");
- break;
- case DM_CMP_STATE_WAITING_FOR_REQUIRED :
- info->state = strdup("WAITING_FOR_REQUIRED");
- break;
- case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED :
- info->state = strdup("INSTANTIATED_AND_WAITING_FOR_REQUIRED");
- break;
- case DM_CMP_STATE_TRACKING_OPTIONAL :
- info->state = strdup("TRACKING_OPTIONAL");
- info->active = true;
- break;
- default :
- info->state = strdup("UNKNOWN");
- break;
- }
- } else {
- status = CELIX_ENOMEM;
+ switch (component->state) {
+ case DM_CMP_STATE_INACTIVE :
+ info->state = strdup("INACTIVE");
+ break;
+ case DM_CMP_STATE_WAITING_FOR_REQUIRED :
+ info->state = strdup("WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED :
+ info->state = strdup("INSTANTIATED_AND_WAITING_FOR_REQUIRED");
+ break;
+ case DM_CMP_STATE_TRACKING_OPTIONAL :
+ info->state = strdup("TRACKING_OPTIONAL");
+ info->active = true;
+ break;
+ default :
+ info->state = strdup("UNKNOWN");
+ break;
}
-
celixThreadMutex_lock(&component->mutex);
size = arrayList_size(component->dependencies);
for (i = 0; i < size; i += 1) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dependency_manager/private/src/dm_service_dependency.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_service_dependency.c b/dependency_manager/private/src/dm_service_dependency.c
index 733f7fd..4f63c6d 100644
--- a/dependency_manager/private/src/dm_service_dependency.c
+++ b/dependency_manager/private/src/dm_service_dependency.c
@@ -150,7 +150,7 @@ celix_status_t serviceDependency_getStrategy(dm_service_dependency_pt dependency
celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName, char *serviceVersionRange, char *filter) {
celix_status_t status = CELIX_SUCCESS;
- if (!dependency) {
+ if (!dependency || !serviceName) {
status = CELIX_ILLEGAL_ARGUMENT;
}
@@ -158,9 +158,7 @@ celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency,
array_list_pt filterElements = NULL;
arrayList_create(&filterElements);
- if (serviceName != NULL) {
- dependency->tracked_service = strdup(serviceName);
- }
+ dependency->tracked_service = strdup(serviceName);
if (serviceVersionRange != NULL) {
version_range_pt versionRange = NULL;
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dependency_manager/private/src/dm_shell_activator.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_activator.c b/dependency_manager/private/src/dm_shell_activator.c
index fcb42cd..89234c7 100644
--- a/dependency_manager/private/src/dm_shell_activator.c
+++ b/dependency_manager/private/src/dm_shell_activator.c
@@ -39,26 +39,19 @@ typedef struct bundle_instance * bundle_instance_pt;
celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+ if(userData==NULL){
+ return CELIX_ILLEGAL_ARGUMENT;
+ }
+
struct bundle_instance *bi = calloc(sizeof (struct bundle_instance), 1);
- celix_status_t status = CELIX_SUCCESS;
- if (!bi) {
- status = CELIX_ENOMEM;
- }
- else if (userData == NULL) {
- status = CELIX_ILLEGAL_ARGUMENT;
- free(bi);
+ if (bi==NULL) {
+ return CELIX_ENOMEM;
}
- else {
- if (status != CELIX_SUCCESS) {
- printf("DM:LIST Create failed\n");
- free(bi);
- }
- (*userData) = bi;
- }
+ (*userData) = bi;
- return status;
+ return CELIX_SUCCESS;
}
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dependency_manager/private/src/dm_shell_list_command.c
----------------------------------------------------------------------
diff --git a/dependency_manager/private/src/dm_shell_list_command.c b/dependency_manager/private/src/dm_shell_list_command.c
index 6f95eb9..be4eaf4 100644
--- a/dependency_manager/private/src/dm_shell_list_command.c
+++ b/dependency_manager/private/src/dm_shell_list_command.c
@@ -43,6 +43,12 @@ void dmListCommand_execute(bundle_context_pt context, char * line, FILE *out, FI
array_list_pt servRefs = NULL;
int i;
bundleContext_getServiceReferences(context, DM_INFO_SERVICE_NAME ,NULL, &servRefs);
+
+ if(servRefs==NULL){
+ fprintf(out, "Invalid dm_info ServiceReferences List\n");
+ return;
+ }
+
char *term = getenv("TERM");
bool colors = false;
if (strcmp("xterm-256color", term) == 0) {
@@ -109,7 +115,7 @@ void dmListCommand_execute(bundle_context_pt context, char * line, FILE *out, FI
bundleContext_ungetService(context,servRef,NULL);
bundleContext_ungetServiceReference(context,servRef);
- }
+ }
if(servRefs!=NULL){
arrayList_destroy(servRefs);
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/deployment_admin/private/src/deployment_admin.c
----------------------------------------------------------------------
diff --git a/deployment_admin/private/src/deployment_admin.c b/deployment_admin/private/src/deployment_admin.c
index 97cc7e1..2c4b9ee 100644
--- a/deployment_admin/private/src/deployment_admin.c
+++ b/deployment_admin/private/src/deployment_admin.c
@@ -295,7 +295,9 @@ static void *deploymentAdmin_poll(void *deploymentAdmin) {
uuid_generate(uid);
uuid_unparse(uid, uuid);
snprintf(tmpDir, 256, "%s%s", entry, uuid);
- mkdir(tmpDir, S_IRWXU);
+ if( mkdir(tmpDir, S_IRWXU) == -1){
+ fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Failed creating directory %s",tmpDir);
+ }
// TODO: update to use bundle cache DataFile instead of module entries.
unzip_extractDeploymentPackage(inputFilename, tmpDir);
@@ -338,7 +340,9 @@ static void *deploymentAdmin_poll(void *deploymentAdmin) {
deploymentAdmin_deleteTree(repoCache);
deploymentAdmin_deleteTree(tmpDir);
- remove(inputFilename);
+ if( remove(inputFilename) == -1){
+ fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Remove of %s failed",inputFilename);
+ }
admin->current = strdup(last);
hashMap_put(admin->packages, name, source);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/device_access/device_access/private/src/device_manager.c
----------------------------------------------------------------------
diff --git a/device_access/device_access/private/src/device_manager.c b/device_access/device_access/private/src/device_manager.c
index b39e5af..dea4513 100644
--- a/device_access/device_access/private/src/device_manager.c
+++ b/device_access/device_access/private/src/device_manager.c
@@ -75,9 +75,11 @@ celix_status_t deviceManager_create(bundle_context_pt context, log_helper_pt log
(*manager)->loghelper = logHelper;
status = arrayList_create(&(*manager)->locators);
+
+ logHelper_log((*manager)->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Initialized");
}
- logHelper_log((*manager)->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Initialized");
+
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/device_access/driver_locator/private/src/activator.c
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/private/src/activator.c b/device_access/driver_locator/private/src/activator.c
index f17ae67..6c13e10 100644
--- a/device_access/driver_locator/private/src/activator.c
+++ b/device_access/driver_locator/private/src/activator.c
@@ -51,23 +51,28 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
celix_status_t status = CELIX_SUCCESS;
bundle_instance_pt bi = (bundle_instance_pt)userData;
- if (status == CELIX_SUCCESS) {
- bi->service = calloc(1, sizeof(*(bi->service)));
- bi->service->findDrivers = driverLocator_findDrivers;
- bi->service->loadDriver = driverLocator_loadDriver;
- bi->locator = calloc(1, sizeof(*(bi->locator)));
- bi->service->locator = bi->locator;
- bi->locator->drivers = NULL;
- arrayList_create(&bi->locator->drivers);
- bundleContext_getProperty(context, "DRIVER_LOCATOR_PATH", &bi->locator->path);
- if (bi->locator->path == NULL ) {
- bi->locator->path = (char *)DEFAULT_LOCATOR_PATH;
- }
- bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_LOCATOR_SERVICE_NAME, bi->service, NULL, &bi->locatorRegistration);
- } else {
- status = CELIX_START_ERROR;
+ bi->service = calloc(1, sizeof(*(bi->service)));
+ bi->locator = calloc(1, sizeof(*(bi->locator)));
+ if(bi->service != NULL && bi->locator != NULL){
+ bi->service->findDrivers = driverLocator_findDrivers;
+ bi->service->loadDriver = driverLocator_loadDriver;
+
+ bi->service->locator = bi->locator;
+ bi->locator->drivers = NULL;
+ arrayList_create(&bi->locator->drivers);
+ bundleContext_getProperty(context, "DRIVER_LOCATOR_PATH", &bi->locator->path);
+ if (bi->locator->path == NULL ) {
+ bi->locator->path = (char *)DEFAULT_LOCATOR_PATH;
+ }
+ status = bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_LOCATOR_SERVICE_NAME, bi->service, NULL, &bi->locatorRegistration);
}
+ else{
+ if(bi->service!=NULL) free(bi->service);
+ if(bi->locator!=NULL) free(bi->locator);
+ status = CELIX_ENOMEM;
+ }
+
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/src/dyn_function.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_function.c b/dfi/private/src/dyn_function.c
index 3727f8a..615ad16 100644
--- a/dfi/private/src/dyn_function.c
+++ b/dfi/private/src/dyn_function.c
@@ -157,7 +157,7 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
dyn_function_argument_type *arg = NULL;
status = dynType_parse(descriptor, NULL, dynFunc->refTypes, &type);
- if (status == 0) {
+ if (status == OK) {
arg = calloc(1, sizeof(*arg));
if (arg != NULL) {
arg->index = index;
@@ -174,15 +174,8 @@ static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descrip
if (status == OK) {
TAILQ_INSERT_TAIL(&dynFunc->arguments, arg, entries);
- } else {
- if (arg != NULL) {
- free(arg->name);
- if (arg->type != NULL) {
- dynType_destroy(arg->type);
- }
- free(arg);
- }
}
+
nextChar = fgetc(descriptor);
}
@@ -217,7 +210,7 @@ static int dynFunction_initCif(dyn_function_type *dynFunc) {
count +=1;
}
- dynFunc->ffiArguments = calloc(count, sizeof(ffi_type));
+ dynFunc->ffiArguments = calloc(count, sizeof(ffi_type*));
TAILQ_FOREACH(entry, &dynFunc->arguments, entries) {
dynFunc->ffiArguments[entry->index] = dynType_ffiType(entry->type);
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/src/dyn_interface.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_interface.c b/dfi/private/src/dyn_interface.c
index fdd872d..cbd675b 100644
--- a/dfi/private/src/dyn_interface.c
+++ b/dfi/private/src/dyn_interface.c
@@ -57,12 +57,12 @@ int dynInterface_parse(FILE *descriptor, dyn_interface_type **out) {
TAILQ_INIT(&intf->types);
TAILQ_INIT(&intf->methods);
- char peek = fgetc(descriptor);
+ char peek = (char)fgetc(descriptor);
while (peek == ':') {
ungetc(peek, descriptor);
status = dynInterface_parseSection(intf, descriptor);
if (status == OK) {
- peek = fgetc(descriptor);
+ peek = (char)fgetc(descriptor);
} else {
break;
}
@@ -217,9 +217,6 @@ static int dynInterface_parseNameValueSection(dyn_interface_type *intf, FILE *st
if (value != NULL) {
free(value);
}
- if (entry != NULL) {
- free(entry);
- }
break;
}
peek = fgetc(stream);
@@ -272,9 +269,6 @@ static int dynInterface_parseTypes(dyn_interface_type *intf, FILE *stream) {
if (type != NULL) {
dynType_destroy(type);
}
- if (entry != NULL) {
- free(entry);
- }
break;
}
peek = fgetc(stream);
@@ -344,9 +338,6 @@ static int dynInterface_parseMethods(dyn_interface_type *intf, FILE *stream) {
dynFunction_destroy(func);
//TODO free strIdentier, name
}
- if (entry != NULL) {
- free(entry);
- }
break;
}
peek = fgetc(stream);
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/src/dyn_message.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_message.c b/dfi/private/src/dyn_message.c
index 5ec6c7a..3e2ca99 100644
--- a/dfi/private/src/dyn_message.c
+++ b/dfi/private/src/dyn_message.c
@@ -55,12 +55,12 @@ int dynMessage_parse(FILE *descriptor, dyn_message_type **out) {
TAILQ_INIT(&msg->annotations);
TAILQ_INIT(&msg->types);
- char peek = fgetc(descriptor);
+ char peek = (char)fgetc(descriptor);
while (peek == ':') {
ungetc(peek, descriptor);
status = dynMessage_parseSection(msg, descriptor);
if (status == OK) {
- peek = fgetc(descriptor);
+ peek = (char)fgetc(descriptor);
} else {
break;
}
@@ -205,9 +205,6 @@ static int dynMessage_parseNameValueSection(dyn_message_type *msg, FILE *stream,
if (value != NULL) {
free(value);
}
- if (entry != NULL) {
- free(entry);
- }
break;
}
peek = fgetc(stream);
@@ -260,9 +257,6 @@ static int dynMessage_parseTypes(dyn_message_type *msg, FILE *stream) {
if (type != NULL) {
dynType_destroy(type);
}
- if (entry != NULL) {
- free(entry);
- }
break;
}
peek = fgetc(stream);
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/src/dyn_type.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_type.c b/dfi/private/src/dyn_type.c
index 24fd09c..2b83f25 100644
--- a/dfi/private/src/dyn_type.c
+++ b/dfi/private/src/dyn_type.c
@@ -313,7 +313,7 @@ static int dynType_parseComplex(FILE *stream, dyn_type *type) {
if (status == OK) {
type->complex.structType.type = FFI_TYPE_STRUCT;
- type->complex.structType.elements = calloc(count + 1, sizeof(ffi_type));
+ type->complex.structType.elements = calloc(count + 1, sizeof(ffi_type*));
if (type->complex.structType.elements != NULL) {
type->complex.structType.elements[count] = NULL;
int index = 0;
@@ -328,7 +328,7 @@ static int dynType_parseComplex(FILE *stream, dyn_type *type) {
if (status == OK) {
type->complex.types = calloc(count, sizeof(dyn_type *));
- if (type != NULL) {
+ if (type->complex.types != NULL) {
int index = 0;
TAILQ_FOREACH(entry, &type->complex.entriesHead, entries) {
type->complex.types[index++] = entry->type;
@@ -635,6 +635,7 @@ int dynType_complex_indexForName(dyn_type *type, const char *name) {
int dynType_complex_dynTypeAt(dyn_type *type, int index, dyn_type **result) {
assert(type->type == DYN_TYPE_COMPLEX);
+ assert(index >= 0);
dyn_type *sub = type->complex.types[index];
if (sub->type == DYN_TYPE_REF) {
sub = sub->ref.ref;
@@ -656,7 +657,7 @@ int dynType_complex_valLocAt(dyn_type *type, int index, void *inst, void **resul
char *l = (char *)inst;
void *loc = (void *)(l + dynType_getOffset(type, index));
*result = loc;
- return 0;
+ return OK;
}
int dynType_complex_entries(dyn_type *type, struct complex_type_entries_head **entries) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/src/json_rpc.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/json_rpc.c b/dfi/private/src/json_rpc.c
index 20d453d..72e3c7e 100644
--- a/dfi/private/src/json_rpc.c
+++ b/dfi/private/src/json_rpc.c
@@ -35,302 +35,305 @@ DFI_SETUP_LOG(jsonRpc);
typedef void (*gen_func_type)(void);
struct generic_service_layout {
- void *handle;
- gen_func_type methods[];
+ void *handle;
+ gen_func_type methods[];
};
int jsonRpc_call(dyn_interface_type *intf, void *service, const char *request, char **out) {
- int status = OK;
-
- dyn_type* returnType = NULL;
-
- LOG_DEBUG("Parsing data: %s\n", request);
- json_error_t error;
- json_t *js_request = json_loads(request, 0, &error);
- json_t *arguments = NULL;
- const char *sig;
- if (js_request) {
- if (json_unpack(js_request, "{s:s}", "m", &sig) != 0) {
- LOG_ERROR("Got json error '%s'\n", error.text);
- } else {
- arguments = json_object_get(js_request, "a");
- }
- } else {
- LOG_ERROR("Got json error '%s' for '%s'\n", error.text, request);
- return 0;
- }
-
- LOG_DEBUG("Looking for method %s\n", sig);
- struct methods_head *methods = NULL;
- dynInterface_methods(intf, &methods);
- struct method_entry *entry = NULL;
- struct method_entry *method = NULL;
- TAILQ_FOREACH(entry, methods, entries) {
- if (strcmp(sig, entry->id) == 0) {
- method = entry;
- break;
- }
- }
-
- if (method == NULL) {
- status = ERROR;
- LOG_ERROR("Cannot find method with sig '%s'", sig);
- }
-
- if (status == OK) {
- LOG_DEBUG("RSA: found method '%s'\n", entry->id);
- returnType = dynFunction_returnType(method->dynFunc);
- }
-
- void (*fp)(void) = NULL;
- void *handle = NULL;
- if (status == OK) {
- struct generic_service_layout *serv = service;
- handle = serv->handle;
- fp = serv->methods[method->index];
- }
-
- dyn_function_type *func = NULL;
- int nrOfArgs = 0;
- if (status == OK) {
- nrOfArgs = dynFunction_nrOfArguments(entry->dynFunc);
- func = entry->dynFunc;
- }
-
- void *args[nrOfArgs];
-
- json_t *value = NULL;
-
- int i;
- int index = 0;
-
- void *ptr = NULL;
- void *ptrToPtr = &ptr;
-
- for (i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
- value = json_array_get(arguments, index++);
- status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
- dynType_alloc(argType, &args[i]);
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
- args[i] = &ptrToPtr;
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__HANDLE) {
- args[i] = &handle;
- }
-
- if (status != OK) {
- break;
- }
- }
- json_decref(js_request);
-
- if (status == OK) {
+ int status = OK;
+
+ dyn_type* returnType = NULL;
+
+ LOG_DEBUG("Parsing data: %s\n", request);
+ json_error_t error;
+ json_t *js_request = json_loads(request, 0, &error);
+ json_t *arguments = NULL;
+ const char *sig;
+ if (js_request) {
+ if (json_unpack(js_request, "{s:s}", "m", &sig) != 0) {
+ LOG_ERROR("Got json error '%s'\n", error.text);
+ } else {
+ arguments = json_object_get(js_request, "a");
+ }
+ } else {
+ LOG_ERROR("Got json error '%s' for '%s'\n", error.text, request);
+ return 0;
+ }
+
+ LOG_DEBUG("Looking for method %s\n", sig);
+ struct methods_head *methods = NULL;
+ dynInterface_methods(intf, &methods);
+ struct method_entry *entry = NULL;
+ struct method_entry *method = NULL;
+ TAILQ_FOREACH(entry, methods, entries) {
+ if (strcmp(sig, entry->id) == 0) {
+ method = entry;
+ break;
+ }
+ }
+
+ if (method == NULL) {
+ status = ERROR;
+ LOG_ERROR("Cannot find method with sig '%s'", sig);
+ }
+ else if (status == OK) {
+ LOG_DEBUG("RSA: found method '%s'\n", entry->id);
+ returnType = dynFunction_returnType(method->dynFunc);
+ }
+
+ void (*fp)(void) = NULL;
+ void *handle = NULL;
+ if (status == OK) {
+ struct generic_service_layout *serv = service;
+ handle = serv->handle;
+ fp = serv->methods[method->index];
+ }
+
+ dyn_function_type *func = NULL;
+ int nrOfArgs = 0;
+ if (status == OK) {
+ nrOfArgs = dynFunction_nrOfArguments(entry->dynFunc);
+ func = entry->dynFunc;
+ }
+
+ void *args[nrOfArgs];
+
+ json_t *value = NULL;
+
+ int i;
+ int index = 0;
+
+ void *ptr = NULL;
+ void *ptrToPtr = &ptr;
+
+ for (i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
+ value = json_array_get(arguments, index++);
+ status = jsonSerializer_deserializeJson(argType, value, &(args[i]));
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
+ dynType_alloc(argType, &args[i]);
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
+ args[i] = &ptrToPtr;
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__HANDLE) {
+ args[i] = &handle;
+ }
+
+ if (status != OK) {
+ break;
+ }
+ }
+ json_decref(js_request);
+
+ if (status == OK) {
if (dynType_descriptorType(returnType) != 'N') {
//NOTE To be able to handle exception only N as returnType is supported
LOG_ERROR("Only interface methods with a native int are supported. Found type '%c'", (char)dynType_descriptorType(returnType));
status = ERROR;
}
- }
-
- ffi_sarg returnVal = 1;
-
- if (status == OK) {
- dynFunction_call(func, fp, (void *) &returnVal, args);
- }
-
- int funcCallStatus = (int)returnVal;
- if (funcCallStatus != 0) {
- LOG_WARNING("Error calling remote endpoint function, got error code %i", funcCallStatus);
- }
-
- json_t *jsonResult = NULL;
- for(i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
- dynType_free(argType, args[i]);
- }
- }
-
- if (funcCallStatus == 0 && status == OK) {
- for (i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
- if (status == OK) {
- status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
- }
- dynType_free(argType, args[i]);
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
- if (ptr != NULL) {
- dyn_type *typedType = NULL;
- if (status == OK) {
- status = dynType_typedPointer_getTypedType(argType, &typedType);
- }
- if (dynType_descriptorType(typedType) == 't') {
- status = jsonSerializer_serializeJson(typedType, (void*) &ptr, &jsonResult);
- free(ptr);
- } else {
- dyn_type *typedTypedType = NULL;
- if (status == OK) {
- status = dynType_typedPointer_getTypedType(typedType, &typedTypedType);
- }
-
- status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult);
-
- if (status == OK) {
- dynType_free(typedTypedType, ptr);
- }
- }
-
- } else {
- LOG_DEBUG("Output ptr is null");
- }
- }
-
- if (status != OK) {
- break;
- }
- }
- }
-
- char *response = NULL;
- if (status == OK) {
- LOG_DEBUG("creating payload\n");
- json_t *payload = json_object();
- if (funcCallStatus == 0) {
- if (jsonResult == NULL) {
- //ignore -> no result
- } else {
- LOG_DEBUG("Setting result payload");
- json_object_set_new(payload, "r", jsonResult);
- }
- } else {
- LOG_DEBUG("Setting error payload");
- json_object_set_new(payload, "e", json_integer(funcCallStatus));
- }
- response = json_dumps(payload, JSON_DECODE_ANY);
- json_decref(payload);
- LOG_DEBUG("status ptr is %p. response is '%s'\n", status, response);
- }
-
- if (status == OK) {
- *out = response;
- } else {
- free(response);
- }
-
- return status;
+ }
+
+ ffi_sarg returnVal = 1;
+
+ if (status == OK) {
+ dynFunction_call(func, fp, (void *) &returnVal, args);
+ }
+
+ int funcCallStatus = (int)returnVal;
+ if (funcCallStatus != 0) {
+ LOG_WARNING("Error calling remote endpoint function, got error code %i", funcCallStatus);
+ }
+
+ json_t *jsonResult = NULL;
+ for(i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
+ dynType_free(argType, args[i]);
+ }
+ }
+
+ if (funcCallStatus == 0 && status == OK) {
+ for (i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
+ if (status == OK) {
+ status = jsonSerializer_serializeJson(argType, args[i], &jsonResult);
+ }
+ dynType_free(argType, args[i]);
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
+ if (ptr != NULL) {
+ dyn_type *typedType = NULL;
+ if (status == OK) {
+ status = dynType_typedPointer_getTypedType(argType, &typedType);
+ }
+ if (dynType_descriptorType(typedType) == 't') {
+ status = jsonSerializer_serializeJson(typedType, (void*) &ptr, &jsonResult);
+ free(ptr);
+ } else {
+ dyn_type *typedTypedType = NULL;
+ if (status == OK) {
+ status = dynType_typedPointer_getTypedType(typedType, &typedTypedType);
+ }
+
+ status = jsonSerializer_serializeJson(typedTypedType, ptr, &jsonResult);
+
+ if (status == OK) {
+ dynType_free(typedTypedType, ptr);
+ }
+ }
+
+ } else {
+ LOG_DEBUG("Output ptr is null");
+ }
+ }
+
+ if (status != OK) {
+ break;
+ }
+ }
+ }
+
+ char *response = NULL;
+ if (status == OK) {
+ LOG_DEBUG("creating payload\n");
+ json_t *payload = json_object();
+ if (funcCallStatus == 0) {
+ if (jsonResult == NULL) {
+ //ignore -> no result
+ } else {
+ LOG_DEBUG("Setting result payload");
+ json_object_set_new(payload, "r", jsonResult);
+ }
+ } else {
+ LOG_DEBUG("Setting error payload");
+ json_object_set_new(payload, "e", json_integer(funcCallStatus));
+ }
+ response = json_dumps(payload, JSON_DECODE_ANY);
+ json_decref(payload);
+ LOG_DEBUG("status ptr is %p. response is '%s'\n", status, response);
+ }
+
+ if (status == OK) {
+ *out = response;
+ } else {
+ free(response);
+ }
+
+ return status;
}
int jsonRpc_prepareInvokeRequest(dyn_function_type *func, const char *id, void *args[], char **out) {
- int status = OK;
-
-
- LOG_DEBUG("Calling remote function '%s'\n", id);
- json_t *invoke = json_object();
- json_object_set_new(invoke, "m", json_string(id));
-
- json_t *arguments = json_array();
- json_object_set_new(invoke, "a", arguments);
-
- int i;
- int nrOfArgs = dynFunction_nrOfArguments(func);
- for (i = 0; i < nrOfArgs; i +=1) {
- dyn_type *type = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
- json_t *val = NULL;
-
- int rc = jsonSerializer_serializeJson(type, args[i], &val);
- if (rc == 0) {
- json_array_append_new(arguments, val);
- } else {
- status = ERROR;
- break;
- }
- } else {
- //skip handle / output types
- }
- }
-
- char *invokeStr = json_dumps(invoke, JSON_DECODE_ANY);
- json_decref(invoke);
-
- if (status == OK) {
- *out = invokeStr;
- }
-
- return status;
+ int status = OK;
+
+
+ LOG_DEBUG("Calling remote function '%s'\n", id);
+ json_t *invoke = json_object();
+ json_object_set_new(invoke, "m", json_string(id));
+
+ json_t *arguments = json_array();
+ json_object_set_new(invoke, "a", arguments);
+
+ int i;
+ int nrOfArgs = dynFunction_nrOfArguments(func);
+ for (i = 0; i < nrOfArgs; i +=1) {
+ dyn_type *type = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__STD) {
+ json_t *val = NULL;
+
+ int rc = jsonSerializer_serializeJson(type, args[i], &val);
+ if (rc == 0) {
+ json_array_append_new(arguments, val);
+ } else {
+ status = ERROR;
+ break;
+ }
+ } else {
+ //skip handle / output types
+ }
+ }
+
+ char *invokeStr = json_dumps(invoke, JSON_DECODE_ANY);
+ json_decref(invoke);
+
+ if (status == OK) {
+ *out = invokeStr;
+ }
+
+ return status;
}
int jsonRpc_handleReply(dyn_function_type *func, const char *reply, void *args[]) {
- int status = OK;
-
- json_error_t error;
- json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, &error);
- if (replyJson == NULL) {
- status = ERROR;
- LOG_ERROR("Error parsing json '%s', got error '%s'", reply, error.text);
- }
-
- json_t *result = NULL;
- if (status == OK) {
- result = json_object_get(replyJson, "r"); //TODO check
- if (result == NULL) {
- status = ERROR;
- LOG_ERROR("Cannot find r entry in json reply '%s'", reply);
- }
- }
-
- if (status == OK) {
- int nrOfArgs = dynFunction_nrOfArguments(func);
- int i;
- for (i = 0; i < nrOfArgs; i += 1) {
- dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
- enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
- if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
- void *tmp = NULL;
- void **out = (void **) args[i];
-
- size_t size = 0;
-
- if (dynType_descriptorType(argType) == 't') {
- status = jsonSerializer_deserializeJson(argType, result, &tmp);
- size = strnlen(((char *) *(char**) tmp), 1024 * 1024);
- memcpy(*out, *(void**) tmp, size);
- } else {
- dynType_typedPointer_getTypedType(argType, &argType);
- status = jsonSerializer_deserializeJson(argType, result, &tmp);
- size = dynType_size(argType);
- memcpy(*out, tmp, size);
- }
-
- dynType_free(argType, tmp);
- } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
- dyn_type *subType = NULL;
-
- dynType_typedPointer_getTypedType(argType, &subType);
-
- if (dynType_descriptorType(subType) == 't') {
- void ***out = (void ***) args[i];
- status = jsonSerializer_deserializeJson(subType, result, *out);
- } else {
- dyn_type *subSubType = NULL;
- dynType_typedPointer_getTypedType(subType, &subSubType);
- void ***out = (void ***) args[i];
- status = jsonSerializer_deserializeJson(subSubType, result, *out);
- }
- } else {
- //skip
- }
- }
- }
-
- json_decref(replyJson);
-
- return status;
+ int status = OK;
+
+ json_error_t error;
+ json_t *replyJson = json_loads(reply, JSON_DECODE_ANY, &error);
+ if (replyJson == NULL) {
+ status = ERROR;
+ LOG_ERROR("Error parsing json '%s', got error '%s'", reply, error.text);
+ }
+
+ json_t *result = NULL;
+ if (status == OK) {
+ result = json_object_get(replyJson, "r"); //TODO check
+ if (result == NULL) {
+ status = ERROR;
+ LOG_ERROR("Cannot find r entry in json reply '%s'", reply);
+ }
+ }
+
+ if (status == OK) {
+ int nrOfArgs = dynFunction_nrOfArguments(func);
+ int i;
+ for (i = 0; i < nrOfArgs; i += 1) {
+ dyn_type *argType = dynFunction_argumentTypeForIndex(func, i);
+ enum dyn_function_argument_meta meta = dynFunction_argumentMetaForIndex(func, i);
+ if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
+ void *tmp = NULL;
+ void **out = (void **) args[i];
+
+ size_t size = 0;
+
+ if (dynType_descriptorType(argType) == 't') {
+ status = jsonSerializer_deserializeJson(argType, result, &tmp);
+ if(tmp!=NULL){
+ size = strnlen(((char *) *(char**) tmp), 1024 * 1024);
+ memcpy(*out, *(void**) tmp, size);
+ }
+ } else {
+ dynType_typedPointer_getTypedType(argType, &argType);
+ status = jsonSerializer_deserializeJson(argType, result, &tmp);
+ if(tmp!=NULL){
+ size = dynType_size(argType);
+ memcpy(*out, tmp, size);
+ }
+ }
+
+ dynType_free(argType, tmp);
+ } else if (meta == DYN_FUNCTION_ARGUMENT_META__OUTPUT) {
+ dyn_type *subType = NULL;
+
+ dynType_typedPointer_getTypedType(argType, &subType);
+
+ if (dynType_descriptorType(subType) == 't') {
+ void ***out = (void ***) args[i];
+ status = jsonSerializer_deserializeJson(subType, result, *out);
+ } else {
+ dyn_type *subSubType = NULL;
+ dynType_typedPointer_getTypedType(subType, &subSubType);
+ void ***out = (void ***) args[i];
+ status = jsonSerializer_deserializeJson(subSubType, result, *out);
+ }
+ } else {
+ //skip
+ }
+ }
+ }
+
+ json_decref(replyJson);
+
+ return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/src/json_serializer.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/json_serializer.c b/dfi/private/src/json_serializer.c
index 85ba782..0c06998 100644
--- a/dfi/private/src/json_serializer.c
+++ b/dfi/private/src/json_serializer.c
@@ -448,8 +448,14 @@ static int jsonSerializer_writeComplex(dyn_type *type, void *input, json_t **out
json_t *subVal = NULL;
dyn_type *subType = NULL;
index = dynType_complex_indexForName(type, entry->name);
- status = dynType_complex_valLocAt(type, index, input, &subLoc);
- if (status == OK ) {
+ if (index < 0) {
+ LOG_ERROR("Cannot find index for member '%s'", entry->name);
+ status = ERROR;
+ }
+ if(status == OK){
+ status = dynType_complex_valLocAt(type, index, input, &subLoc);
+ }
+ if (status == OK) {
status = dynType_complex_dynTypeAt(type, index, &subType);
}
if (status == OK) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/test/avro_descriptor_translator_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/avro_descriptor_translator_tests.cpp b/dfi/private/test/avro_descriptor_translator_tests.cpp
index c29932e..5bab518 100644
--- a/dfi/private/test/avro_descriptor_translator_tests.cpp
+++ b/dfi/private/test/avro_descriptor_translator_tests.cpp
@@ -40,6 +40,7 @@ extern "C" {
va_start(ap, msg);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
+ va_end(ap);
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/test/dyn_closure_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_closure_tests.cpp b/dfi/private/test/dyn_closure_tests.cpp
index ce70f93..5f13de4 100644
--- a/dfi/private/test/dyn_closure_tests.cpp
+++ b/dfi/private/test/dyn_closure_tests.cpp
@@ -39,6 +39,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
va_start(ap, msg);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
+ va_end(ap);
}
#define EXAMPLE1_DESCRIPTOR "example(III)I"
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/test/dyn_function_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_function_tests.cpp b/dfi/private/test/dyn_function_tests.cpp
index 1b65be8..34d7116 100644
--- a/dfi/private/test/dyn_function_tests.cpp
+++ b/dfi/private/test/dyn_function_tests.cpp
@@ -37,6 +37,7 @@ extern "C" {
va_start(ap, msg);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
+ va_end(ap);
}
#define EXAMPLE1_DESCRIPTOR "example(III)I"
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/test/dyn_message_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_message_tests.cpp b/dfi/private/test/dyn_message_tests.cpp
index 7aafcc3..18c5505 100644
--- a/dfi/private/test/dyn_message_tests.cpp
+++ b/dfi/private/test/dyn_message_tests.cpp
@@ -43,6 +43,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
va_start(ap, msg);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
+ va_end(ap);
}
static void checkMessageVersion(dyn_message_type* dynMsg, const char* v){
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/test/dyn_type_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_type_tests.cpp b/dfi/private/test/dyn_type_tests.cpp
index db95da4..e65c2b9 100644
--- a/dfi/private/test/dyn_type_tests.cpp
+++ b/dfi/private/test/dyn_type_tests.cpp
@@ -32,6 +32,7 @@ extern "C" {
va_start(ap, msg);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
+ va_end(ap);
}
static void runTest(const char *descriptorStr, const char *exName) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/test/json_rpc_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/json_rpc_tests.cpp b/dfi/private/test/json_rpc_tests.cpp
index 8b4044d..10097ec 100644
--- a/dfi/private/test/json_rpc_tests.cpp
+++ b/dfi/private/test/json_rpc_tests.cpp
@@ -42,6 +42,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
va_start(ap, msg);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
+ va_end(ap);
}
@@ -138,7 +139,9 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
}
struct tst_StatsResult *result = (struct tst_StatsResult *) calloc(1, sizeof(*result));
- result->average = total / count;
+ if(count>0){
+ result->average = total / count;
+ }
result->min = min;
result->max = max;
double *buf = (double *)calloc(input.len, sizeof(double));
@@ -367,7 +370,9 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
args[0] = NULL;
args[1] = &out;
- rc = jsonRpc_handleReply(func, reply, args);
+ if(func!=NULL){ // Check needed just to satisfy Coverity
+ rc = jsonRpc_handleReply(func, reply, args);
+ }
STRCMP_EQUAL("this is a test string", result);
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/dfi/private/test/json_serializer_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/json_serializer_tests.cpp b/dfi/private/test/json_serializer_tests.cpp
index f4e9f2d..bd65b23 100644
--- a/dfi/private/test/json_serializer_tests.cpp
+++ b/dfi/private/test/json_serializer_tests.cpp
@@ -39,6 +39,7 @@ static void stdLog(void *handle, int level, const char *file, int line, const ch
va_start(ap, msg);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
+ va_end(ap);
}
/*********** example 1 ************************/
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/examples/embedding/private/src/main.c
----------------------------------------------------------------------
diff --git a/examples/embedding/private/src/main.c b/examples/embedding/private/src/main.c
index c04099e..f785121 100644
--- a/examples/embedding/private/src/main.c
+++ b/examples/embedding/private/src/main.c
@@ -35,59 +35,64 @@ struct foo {
};
struct fooSrv {
- struct foo *handle;
- celix_status_t (*foo)(struct foo *handle);
+ struct foo *handle;
+ celix_status_t (*foo)(struct foo *handle);
};
celix_status_t embedded_foo();
int main(void) {
- framework_pt framework = NULL;
+ framework_pt framework = NULL;
- properties_pt config = properties_create();
- int rc = celixLauncher_launchWithProperties(config, &framework);
+ properties_pt config = properties_create();
+ int rc = celixLauncher_launchWithProperties(config, &framework);
- if (rc == 0) {
- bundle_pt fwBundle = NULL;
- framework_getFrameworkBundle(framework, &fwBundle);
- bundle_start(fwBundle);
+ if (rc == 0) {
+ bundle_pt fwBundle = NULL;
+ if(framework_getFrameworkBundle(framework, &fwBundle) == CELIX_SUCCESS){
- bundle_context_pt context = NULL;
- bundle_getContext(fwBundle, &context);
+ if(bundle_start(fwBundle) == CELIX_SUCCESS){
- struct foo *f = calloc(1, sizeof(*f));
- struct fooSrv *fs = calloc(1, sizeof(*fs));
+ bundle_context_pt context = NULL;
+ bundle_getContext(fwBundle, &context);
- fs->handle = f;
- fs->foo = embedded_foo;
+ struct foo *f = calloc(1, sizeof(*f));
+ struct fooSrv *fs = calloc(1, sizeof(*fs));
- service_registration_pt reg = NULL;
- bundleContext_registerService(context, "foo", fs, NULL, ®);
+ fs->handle = f;
+ fs->foo = embedded_foo;
- service_reference_pt ref = NULL;
- bundleContext_getServiceReference(context, "foo", &ref);
+ service_registration_pt reg = NULL;
- void *fs2 = NULL;
- bundleContext_getService(context, ref, &fs2);
+ if(bundleContext_registerService(context, "foo", fs, NULL, ®) == CELIX_SUCCESS){
- ((struct fooSrv*) fs2)->foo(((struct fooSrv*) fs2)->handle);
+ service_reference_pt ref = NULL;
+ if(bundleContext_getServiceReference(context, "foo", &ref) == CELIX_SUCCESS){
- bundleContext_ungetServiceReference(context, ref);
- serviceRegistration_unregister(reg);
+ void *fs2 = NULL;
+ bundleContext_getService(context, ref, &fs2);
- free(f);
- free(fs);
+ ((struct fooSrv*) fs2)->foo(((struct fooSrv*) fs2)->handle);
- celixLauncher_destroy(framework);
- }
+ bundleContext_ungetServiceReference(context, ref);
+ serviceRegistration_unregister(reg);
+ }
+ }
- return rc;
+ free(f);
+ free(fs);
+ }
+ }
+ celixLauncher_destroy(framework);
+ }
+
+ return rc;
}
celix_status_t embedded_foo() {
- printf("foo\n");
- return CELIX_SUCCESS;
+ printf("foo\n");
+ return CELIX_SUCCESS;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/examples/locking/benchmark/private/src/benchmark_runner_activator.c
----------------------------------------------------------------------
diff --git a/examples/locking/benchmark/private/src/benchmark_runner_activator.c b/examples/locking/benchmark/private/src/benchmark_runner_activator.c
index 99af502..c91d68f 100644
--- a/examples/locking/benchmark/private/src/benchmark_runner_activator.c
+++ b/examples/locking/benchmark/private/src/benchmark_runner_activator.c
@@ -209,16 +209,17 @@ static void benchmarkRunner_runBenchmark(struct activator *activator, FILE *out)
updateFrequency = 1000;
nrOfUpdateThreads = 100;
+ benchmarkServ = activator->benchmark;
+ name = benchmarkServ->name(benchmarkServ->handler);
+ sampleFactor = benchmarkServ->getSampleFactor(benchmarkServ->handler);
+
pthread_mutex_lock(&activator->mutex);
if (activator->freqService != NULL) {
activator->freqService->setFrequency(activator->freqService->handle, updateFrequency);
activator->freqService->setNrOfThreads(activator->freqService->handle, nrOfUpdateThreads);
+ activator->freqService->setBenchmarkName(activator->freqService->handle, name);
}
- benchmarkServ = activator->benchmark;
- name = benchmarkServ->name(benchmarkServ->handler);
- sampleFactor = benchmarkServ->getSampleFactor(benchmarkServ->handler);
- activator->freqService->setBenchmarkName(activator->freqService->handle, name);
usleep(1000);
benchmarkRunner_printHeader(name, nrOfSamples * (int)sampleFactor, out);
for (k = 0 ; k < nrOfThreadRuns ; k +=1) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/examples/locking/mutex_benchmark/private/src/mutex_benchmark.c
----------------------------------------------------------------------
diff --git a/examples/locking/mutex_benchmark/private/src/mutex_benchmark.c b/examples/locking/mutex_benchmark/private/src/mutex_benchmark.c
index 07c9c5c..02470b3 100644
--- a/examples/locking/mutex_benchmark/private/src/mutex_benchmark.c
+++ b/examples/locking/mutex_benchmark/private/src/mutex_benchmark.c
@@ -81,8 +81,10 @@ benchmark_result_t benchmark_run(benchmark_pt benchmark, int nrOfThreads, int nr
}
unsigned int actualSamples = (nrOfSamples * nrOfThreads) - result.skips;
+ if(elapsedTime != 0){
result.averageCallTimeInNanoseconds = actualSamples == 0 ? NAN : ((double)elapsedTime * 1000) / (nrOfSamples * nrOfThreads);
result.callFrequencyInMhz = ((double)(actualSamples * nrOfThreads) / elapsedTime);
+ }
result.nrOfThreads = nrOfThreads;
result.nrOfsamples = actualSamples;
result.requestedNrOfSamples = (nrOfSamples * nrOfThreads);
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/examples/mongoose/private/src/mongoose.c
----------------------------------------------------------------------
diff --git a/examples/mongoose/private/src/mongoose.c b/examples/mongoose/private/src/mongoose.c
index b1f0a4b..d133ab3 100644
--- a/examples/mongoose/private/src/mongoose.c
+++ b/examples/mongoose/private/src/mongoose.c
@@ -1930,7 +1930,7 @@ static void MD5Final(unsigned char digest[16], MD5_CTX *ctx) {
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
- memset((char *) ctx, 0, sizeof(ctx));
+ memset((char *) ctx, 0, sizeof(*ctx));
}
#endif // !HAVE_MD5
@@ -2406,12 +2406,14 @@ static void handle_directory_request(struct mg_connection *conn,
conn->request_info.uri, "..", "Parent directory", "-", "-");
// Sort and print directory entries
- qsort(entries, num_entries, sizeof(entries[0]), compare_dir_entries);
- for (i = 0; i < num_entries; i++) {
- print_dir_entry(&entries[i]);
- free(entries[i].file_name);
+ if(entries!=NULL){
+ qsort(entries, num_entries, sizeof(entries[0]), compare_dir_entries);
+ for (i = 0; i < num_entries; i++) {
+ print_dir_entry(&entries[i]);
+ free(entries[i].file_name);
+ }
+ free(entries);
}
- free(entries);
conn->num_bytes_sent += mg_printf(conn, "%s", "</table></body></html>");
conn->request_info.status_code = 200;
@@ -3293,7 +3295,9 @@ static int set_ports_option(struct mg_context *ctx) {
#endif // !_WIN32
bind(sock, &so.lsa.u.sa, so.lsa.len) != 0 ||
listen(sock, 20) != 0) {
- closesocket(sock);
+ if(sock != INVALID_SOCKET ){
+ closesocket(sock);
+ }
cry(fc(ctx), "%s: cannot bind to %.*s: %s", __func__,
vec.len, vec.ptr, strerror(ERRNO));
success = 0;
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/examples/osgi-in-action/chapter04-correct-listener/private/src/listener_example.c
----------------------------------------------------------------------
diff --git a/examples/osgi-in-action/chapter04-correct-listener/private/src/listener_example.c b/examples/osgi-in-action/chapter04-correct-listener/private/src/listener_example.c
index adbf027..7903ad1 100644
--- a/examples/osgi-in-action/chapter04-correct-listener/private/src/listener_example.c
+++ b/examples/osgi-in-action/chapter04-correct-listener/private/src/listener_example.c
@@ -77,7 +77,7 @@ celix_status_t bundleActivator_start(void * userData, bundle_context_pt context)
celix_status_t status = CELIX_SUCCESS;
struct listenerActivator *activator = userData;
- service_listener_pt listener = calloc(1, sizeof(struct listenerActivator));
+ service_listener_pt listener = calloc(1, sizeof(*listener));
if (!listener) {
status = CELIX_ENOMEM;
} else {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
----------------------------------------------------------------------
diff --git a/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c b/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
index 2ada02f..19cf093 100644
--- a/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
+++ b/examples/osgi-in-action/chapter04-correct-lookup/private/src/activator.c
@@ -59,7 +59,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData
*userData = calloc(1, sizeof(struct threadData));
- if (!userData) {
+ if ((*userData)==NULL) {
status = CELIX_ENOMEM;
} else {
((thread_data_pt) (*userData))->service = "chapter04-correct-lookup";
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/mock/celix_log_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/celix_log_mock.c b/framework/private/mock/celix_log_mock.c
index 81e635d..38dd0ae 100644
--- a/framework/private/mock/celix_log_mock.c
+++ b/framework/private/mock/celix_log_mock.c
@@ -69,6 +69,8 @@ static void test_logger_log(framework_logger_pt logger, framework_log_level_t le
vsprintf(msg, fmsg, listPointer);
test_logger_print(level, func, file, line, msg);
+
+ va_end(listPointer);
}
static void test_logger_print(framework_log_level_t level, const char *func, const char *file, int line, char *msg) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/src/bundle_archive.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c
index 74c5dd4..4c838a6 100644
--- a/framework/private/src/bundle_archive.c
+++ b/framework/private/src/bundle_archive.c
@@ -211,8 +211,8 @@ celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt *bun
while (rc == 0 && result != NULL) {
char subdir[512];
snprintf(subdir, 512, "%s/%s", archiveRoot, dent.d_name);
- stat(subdir, &st);
- if (S_ISDIR(st.st_mode) && (strncmp(dent.d_name, "version", 7) == 0)) {
+ int rv = stat(subdir, &st);
+ if (rv == 0 && S_ISDIR(st.st_mode) && (strncmp(dent.d_name, "version", 7) == 0)) {
sscanf(dent.d_name, "version%*d.%ld", &idx);
if (idx > highestId) {
highestId = idx;
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/src/bundle_cache.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_cache.c b/framework/private/src/bundle_cache.c
index 5e5d5dd..6641d5c 100644
--- a/framework/private/src/bundle_cache.c
+++ b/framework/private/src/bundle_cache.c
@@ -86,8 +86,9 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc
dir = opendir(cache->cacheDir);
if (dir == NULL && errno == ENOENT) {
- mkdir(cache->cacheDir, S_IRWXU);
- dir = opendir(cache->cacheDir);
+ if(mkdir(cache->cacheDir, S_IRWXU) == 0 ){
+ dir = opendir(cache->cacheDir);
+ }
}
if (dir != NULL) {
@@ -119,7 +120,7 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc
}
}
- readdir_r(dir, &dp, &result);
+ rc = readdir_r(dir, &dp, &result);
}
if (rc != 0) {
@@ -195,7 +196,7 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * direc
}
}
}
- readdir_r(dir, &dp, &result);
+ rc = readdir_r(dir, &dp, &result);
}
if (closedir(dir) != 0) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/src/celix_launcher.c
----------------------------------------------------------------------
diff --git a/framework/private/src/celix_launcher.c b/framework/private/src/celix_launcher.c
index 144c8dc..7221cc3 100644
--- a/framework/private/src/celix_launcher.c
+++ b/framework/private/src/celix_launcher.c
@@ -40,127 +40,131 @@
#include "linked_list_iterator.h"
int celixLauncher_launch(const char *configFile, framework_pt *framework) {
- int status = 0;
- FILE *config = fopen(configFile, "r");
- if (config != NULL) {
- status = celixLauncher_launchWithStream(config, framework);
- } else {
- fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
- perror("");
- status = 1;
- }
- return status;
+ int status = 0;
+ FILE *config = fopen(configFile, "r");
+ if (config != NULL) {
+ status = celixLauncher_launchWithStream(config, framework);
+ } else {
+ fprintf(stderr, "Error: invalid or non-existing configuration file: '%s'.", configFile);
+ perror("");
+ status = 1;
+ }
+ return status;
}
int celixLauncher_launchWithStream(FILE *stream, framework_pt *framework) {
- int status = 0;
-
- properties_pt config = properties_loadWithStream(stream);
- fclose(stream);
- // Make sure we've read it and that nothing went wrong with the file access...
- if (config == NULL) {
- fprintf(stderr, "Error: invalid configuration file");
- perror(NULL);
- status = 1;
- }
- else {
- status = celixLauncher_launchWithProperties(config, framework);
- }
-
- return status;
+ int status = 0;
+
+ properties_pt config = properties_loadWithStream(stream);
+ fclose(stream);
+ // Make sure we've read it and that nothing went wrong with the file access...
+ if (config == NULL) {
+ fprintf(stderr, "Error: invalid configuration file");
+ perror(NULL);
+ status = 1;
+ }
+ else {
+ status = celixLauncher_launchWithProperties(config, framework);
+ }
+
+ return status;
}
int celixLauncher_launchWithProperties(properties_pt config, framework_pt *framework) {
- celix_status_t status;
+ celix_status_t status;
#ifndef CELIX_NO_CURLINIT
- // Before doing anything else, let's setup Curl
- curl_global_init(CURL_GLOBAL_NOTHING);
+ // Before doing anything else, let's setup Curl
+ curl_global_init(CURL_GLOBAL_NOTHING);
#endif
- char *autoStart = properties_get(config, "cosgi.auto.start.1");
-
- status = framework_create(framework, config);
- bundle_pt fwBundle = NULL;
- if (status == CELIX_SUCCESS) {
- status = fw_init(*framework);
- if (status == CELIX_SUCCESS) {
- // Start the system bundle
- framework_getFrameworkBundle(*framework, &fwBundle);
- bundle_start(fwBundle);
-
- char delims[] = " ";
- char *result = NULL;
- char *save_ptr = NULL;
- linked_list_pt bundles;
- array_list_pt installed = NULL;
- bundle_context_pt context = NULL;
- linked_list_iterator_pt iter = NULL;
- unsigned int i;
-
- linkedList_create(&bundles);
- result = strtok_r(autoStart, delims, &save_ptr);
- while (result != NULL) {
- char *location = strdup(result);
- linkedList_addElement(bundles, location);
- result = strtok_r(NULL, delims, &save_ptr);
- }
- // First install all bundles
- // Afterwards start them
- arrayList_create(&installed);
- bundle_getContext(fwBundle, &context);
- iter = linkedListIterator_create(bundles, 0);
- while (linkedListIterator_hasNext(iter)) {
- bundle_pt current = NULL;
- char *location = (char *) linkedListIterator_next(iter);
- if (bundleContext_installBundle(context, location, ¤t) == CELIX_SUCCESS) {
- // Only add bundle if it is installed correctly
- arrayList_add(installed, current);
- } else {
- printf("Could not install bundle from %s\n", location);
- }
- linkedListIterator_remove(iter);
- free(location);
- }
- linkedListIterator_destroy(iter);
- linkedList_destroy(bundles);
-
- for (i = 0; i < arrayList_size(installed); i++) {
- bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
- bundle_startWithOptions(installedBundle, 0);
- }
-
- arrayList_destroy(installed);
- }
- }
-
- if (status != CELIX_SUCCESS) {
- printf("Problem creating framework\n");
- }
-
- printf("Launcher: Framework Started\n");
-
-
- return status;
+ char *autoStart = properties_get(config, "cosgi.auto.start.1");
+
+ status = framework_create(framework, config);
+ bundle_pt fwBundle = NULL;
+ if (status == CELIX_SUCCESS) {
+ status = fw_init(*framework);
+ if (status == CELIX_SUCCESS) {
+ // Start the system bundle
+ status = framework_getFrameworkBundle(*framework, &fwBundle);
+
+ if(status == CELIX_SUCCESS){
+ bundle_start(fwBundle);
+
+ char delims[] = " ";
+ char *result = NULL;
+ char *save_ptr = NULL;
+ linked_list_pt bundles;
+ array_list_pt installed = NULL;
+ bundle_context_pt context = NULL;
+ linked_list_iterator_pt iter = NULL;
+ unsigned int i;
+
+ linkedList_create(&bundles);
+ result = strtok_r(autoStart, delims, &save_ptr);
+ while (result != NULL) {
+ char *location = strdup(result);
+ linkedList_addElement(bundles, location);
+ result = strtok_r(NULL, delims, &save_ptr);
+ }
+ // First install all bundles
+ // Afterwards start them
+ arrayList_create(&installed);
+ bundle_getContext(fwBundle, &context);
+ iter = linkedListIterator_create(bundles, 0);
+ while (linkedListIterator_hasNext(iter)) {
+ bundle_pt current = NULL;
+ char *location = (char *) linkedListIterator_next(iter);
+ if (bundleContext_installBundle(context, location, ¤t) == CELIX_SUCCESS) {
+ // Only add bundle if it is installed correctly
+ arrayList_add(installed, current);
+ } else {
+ printf("Could not install bundle from %s\n", location);
+ }
+ linkedListIterator_remove(iter);
+ free(location);
+ }
+ linkedListIterator_destroy(iter);
+ linkedList_destroy(bundles);
+
+ for (i = 0; i < arrayList_size(installed); i++) {
+ bundle_pt installedBundle = (bundle_pt) arrayList_get(installed, i);
+ bundle_startWithOptions(installedBundle, 0);
+ }
+
+ arrayList_destroy(installed);
+ }
+ }
+ }
+
+ if (status != CELIX_SUCCESS) {
+ printf("Problem creating framework\n");
+ }
+
+ printf("Launcher: Framework Started\n");
+
+
+ return status;
}
void celixLauncher_waitForShutdown(framework_pt framework) {
- framework_waitForStop(framework);
+ framework_waitForStop(framework);
}
void celixLauncher_destroy(framework_pt framework) {
- framework_destroy(framework);
+ framework_destroy(framework);
- #ifndef CELIX_NO_CURLINIT
- // Cleanup Curl
- curl_global_cleanup();
- #endif
+#ifndef CELIX_NO_CURLINIT
+ // Cleanup Curl
+ curl_global_cleanup();
+#endif
- printf("Launcher: Exit\n");
+ printf("Launcher: Exit\n");
}
void celixLauncher_stop(framework_pt framework) {
- bundle_pt fwBundle = NULL;
- framework_getFrameworkBundle(framework, &fwBundle);
- bundle_stop(fwBundle);
+ bundle_pt fwBundle = NULL;
+ if( framework_getFrameworkBundle(framework, &fwBundle) == CELIX_SUCCESS){
+ bundle_stop(fwBundle);
+ }
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/src/celix_log.c
----------------------------------------------------------------------
diff --git a/framework/private/src/celix_log.c b/framework/private/src/celix_log.c
index d2e222e..7c7e14f 100644
--- a/framework/private/src/celix_log.c
+++ b/framework/private/src/celix_log.c
@@ -38,6 +38,8 @@ void framework_log(framework_logger_pt logger, framework_log_level_t level, cons
if (logger != NULL && logger->logFunction != NULL) {
logger->logFunction(level, func, file, line, msg);
}
+
+ va_end(listPointer);
}
void framework_logCode(framework_logger_pt logger, framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...) {
@@ -49,6 +51,8 @@ void framework_logCode(framework_logger_pt logger, framework_log_level_t level,
vsprintf(msg, fmsg, listPointer);
framework_log(logger, level, func, file, line, "%s [%d]: %s", message, code, msg);
+
+ va_end(listPointer);
}
celix_status_t frameworkLogger_log(framework_log_level_t level, const char *func, const char *file, int line, char *msg) {
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index 2c99f57..3df30c9 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -272,10 +272,12 @@ celix_status_t framework_destroy(framework_pt framework) {
array_list_pt handles = NULL;
status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
status = CELIX_DO_IF(status, bundleRevision_getHandles(revision, &handles));
- for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
- void *handle = arrayList_get(handles, i);
- fw_closeLibrary(handle);
- }
+ if(handles != NULL){
+ for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
+ void *handle = arrayList_get(handles, i);
+ fw_closeLibrary(handle);
+ }
+ }
}
bundleArchive_destroy(archive);
@@ -518,7 +520,6 @@ celix_status_t fw_getProperty(framework_pt framework, const char *name, char **v
if (framework == NULL || name == NULL || *value != NULL) {
status = CELIX_ILLEGAL_ARGUMENT;
- fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, "Missing required arguments");
} else {
if (framework->configurationMap != NULL) {
*value = properties_get(framework->configurationMap, (char *) name);
@@ -792,10 +793,12 @@ celix_status_t framework_updateBundle(framework_pt framework, bundle_pt bundle,
array_list_pt handles = NULL;
status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
status = CELIX_DO_IF(status, bundleRevision_getHandles(revision, &handles));
- for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
- void *handle = arrayList_get(handles, i);
- fw_closeLibrary(handle);
- }
+ if(handles != NULL){
+ for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
+ void *handle = arrayList_get(handles, i);
+ fw_closeLibrary(handle);
+ }
+ }
status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_UNRESOLVED, bundle));
@@ -994,9 +997,11 @@ celix_status_t fw_uninstallBundle(framework_pt framework, bundle_pt bundle) {
array_list_pt handles = NULL;
status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
status = CELIX_DO_IF(status, bundleRevision_getHandles(revision, &handles));
- for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
- void *handle = arrayList_get(handles, i);
- fw_closeLibrary(handle);
+ if(handles != NULL){
+ for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
+ void *handle = arrayList_get(handles, i);
+ fw_closeLibrary(handle);
+ }
}
status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_UNRESOLVED, bundle));
@@ -1168,26 +1173,28 @@ celix_status_t fw_refreshHelper_restart(struct fw_refreshHelper * refreshHelper)
celix_status_t fw_getDependentBundles(framework_pt framework, bundle_pt exporter, array_list_pt *list) {
celix_status_t status = CELIX_SUCCESS;
- if (*list == NULL && exporter != NULL && framework != NULL) {
- array_list_pt modules;
- unsigned int modIdx = 0;
- arrayList_create(list);
-
- modules = bundle_getModules(exporter);
- for (modIdx = 0; modIdx < arrayList_size(modules); modIdx++) {
- module_pt module = (module_pt) arrayList_get(modules, modIdx);
- array_list_pt dependents = module_getDependents(module);
- unsigned int depIdx = 0;
- for (depIdx = 0; (dependents != NULL) && (depIdx < arrayList_size(dependents)); depIdx++) {
- module_pt dependent = (module_pt) arrayList_get(dependents, depIdx);
- arrayList_add(*list, module_getBundle(dependent));
- }
- arrayList_destroy(dependents);
- }
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
+ if (*list != NULL || exporter == NULL || framework == NULL) {
+ return CELIX_ILLEGAL_ARGUMENT;
}
+ array_list_pt modules;
+ unsigned int modIdx = 0;
+ arrayList_create(list);
+
+ modules = bundle_getModules(exporter);
+ for (modIdx = 0; modIdx < arrayList_size(modules); modIdx++) {
+ module_pt module = (module_pt) arrayList_get(modules, modIdx);
+ array_list_pt dependents = module_getDependents(module);
+ if(dependents!=NULL){
+ unsigned int depIdx = 0;
+ for (depIdx = 0; depIdx < arrayList_size(dependents); depIdx++) {
+ module_pt dependent = (module_pt) arrayList_get(dependents, depIdx);
+ arrayList_add(*list, module_getBundle(dependent));
+ }
+ arrayList_destroy(dependents);
+ }
+ }
+
framework_logIfError(framework->logger, status, NULL, "Cannot get dependent bundles");
return status;
@@ -1196,20 +1203,22 @@ celix_status_t fw_getDependentBundles(framework_pt framework, bundle_pt exporter
celix_status_t fw_populateDependentGraph(framework_pt framework, bundle_pt exporter, hash_map_pt *map) {
celix_status_t status = CELIX_SUCCESS;
- if (exporter != NULL && framework != NULL) {
- array_list_pt dependents = NULL;
- if ((status = fw_getDependentBundles(framework, exporter, &dependents)) == CELIX_SUCCESS) {
- unsigned int depIdx = 0;
- for (depIdx = 0; (dependents != NULL) && (depIdx < arrayList_size(dependents)); depIdx++) {
- if (!hashMap_containsKey(*map, arrayList_get(dependents, depIdx))) {
- hashMap_put(*map, arrayList_get(dependents, depIdx), arrayList_get(dependents, depIdx));
- fw_populateDependentGraph(framework, (bundle_pt) arrayList_get(dependents, depIdx), map);
- }
- }
- arrayList_destroy(dependents);
- }
- } else {
- status = CELIX_ILLEGAL_ARGUMENT;
+ if(framework == NULL || exporter == NULL){
+ return CELIX_ILLEGAL_ARGUMENT;
+ }
+
+ array_list_pt dependents = NULL;
+ if ((status = fw_getDependentBundles(framework, exporter, &dependents)) == CELIX_SUCCESS) {
+ if(dependents!=NULL){
+ unsigned int depIdx = 0;
+ for (depIdx = 0; depIdx < arrayList_size(dependents); depIdx++) {
+ if (!hashMap_containsKey(*map, arrayList_get(dependents, depIdx))) {
+ hashMap_put(*map, arrayList_get(dependents, depIdx), arrayList_get(dependents, depIdx));
+ fw_populateDependentGraph(framework, (bundle_pt) arrayList_get(dependents, depIdx), map);
+ }
+ }
+ arrayList_destroy(dependents);
+ }
}
framework_logIfError(framework->logger, status, NULL, "Cannot populate dependent graph");
@@ -1930,16 +1939,17 @@ celix_status_t framework_acquireBundleLock(framework_pt framework, bundle_pt bun
while (!lockable
|| (( celixThread_initalized(framework->globalLockThread) == true)
- && !isSelf)) {
+ && !isSelf))
+ {
bundle_state_e state;
bundle_getState(bundle, &state);
if ((desiredStates & state) == 0) {
status = CELIX_ILLEGAL_STATE;
break;
- } else
- bundle_getLockingThread(bundle, &lockingThread);
- if (isSelf
- && (celixThread_initalized(lockingThread) == true)
+ }
+
+ bundle_getLockingThread(bundle, &lockingThread);
+ if (isSelf && (celixThread_initalized(lockingThread) == true)
&& arrayList_contains(framework->globalLockWaitersList, &lockingThread)) {
framework->interrupted = true;
// celixThreadCondition_signal_thread_np(&framework->condition, bundle_getLockingThread(bundle));
@@ -1952,7 +1962,7 @@ celix_status_t framework_acquireBundleLock(framework_pt framework, bundle_pt bun
if (status != CELIX_SUCCESS) {
break;
}
- }
+ }
if (status == CELIX_SUCCESS) {
bundle_state_e state;
@@ -2170,8 +2180,6 @@ celix_status_t framework_getFrameworkBundle(framework_pt framework, bundle_pt *b
status = CELIX_ILLEGAL_ARGUMENT;
}
- framework_logIfError(framework->logger, status, NULL, "Failed to get framework bundle");
-
return status;
}
@@ -2289,12 +2297,10 @@ celix_status_t fw_fireFrameworkEvent(framework_pt framework, framework_event_typ
status = CELIX_FRAMEWORK_EXCEPTION;
} else {
arrayList_add(framework->requests, request);
- if (celixThreadCondition_broadcast(&framework->dispatcher)) {
- status = CELIX_FRAMEWORK_EXCEPTION;
- } else {
- if (celixThreadMutex_unlock(&framework->dispatcherLock)) {
- status = CELIX_FRAMEWORK_EXCEPTION;
- }
+ celix_status_t bcast_status = celixThreadCondition_broadcast(&framework->dispatcher);
+ celix_status_t unlock_status = celixThreadMutex_unlock(&framework->dispatcherLock);
+ if (bcast_status!=0 || unlock_status!=0) {
+ status = CELIX_FRAMEWORK_EXCEPTION;
}
}
}
@@ -2582,7 +2588,9 @@ static celix_status_t framework_loadLibrary(framework_pt framework, char *librar
status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
status = CELIX_DO_IF(status, bundleRevision_getHandles(revision, &handles));
- arrayList_add(handles, *handle);
+ if(handles != NULL){
+ arrayList_add(handles, *handle);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/src/resolver.c
----------------------------------------------------------------------
diff --git a/framework/private/src/resolver.c b/framework/private/src/resolver.c
index 416ca7c..02d371c 100644
--- a/framework/private/src/resolver.c
+++ b/framework/private/src/resolver.c
@@ -278,7 +278,9 @@ void resolver_addModule(module_pt module) {
}
}
}
- linkedList_addElement(list->capabilities, cap);
+ if(list != NULL){
+ linkedList_addElement(list->capabilities, cap);
+ }
}
}
}
@@ -352,7 +354,9 @@ void resolver_moduleResolved(module_pt module) {
capability_list_pt list;
capability_getServiceName(cap, &serviceName);
list = resolver_getCapabilityList(m_unresolvedServices, serviceName);
- linkedList_removeElement(list->capabilities, cap);
+ if(list != NULL){
+ linkedList_removeElement(list->capabilities, cap);
+ }
linkedList_addElement(capsCopy, cap);
}
@@ -397,7 +401,9 @@ void resolver_moduleResolved(module_pt module) {
}
}
}
- linkedList_addElement(list->capabilities, cap);
+ if(list != NULL){
+ linkedList_addElement(list->capabilities, cap);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/test/bundle_cache_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/bundle_cache_test.cpp b/framework/private/test/bundle_cache_test.cpp
index 1d543d0..f61186c 100644
--- a/framework/private/test/bundle_cache_test.cpp
+++ b/framework/private/test/bundle_cache_test.cpp
@@ -76,11 +76,18 @@ TEST(bundle_cache, deleteTree) {
char cacheFile[] = "bundle_cache_test_directory/tempXXXXXX";
cache->cacheDir = cacheDir;
- mkdir(cacheDir, S_IRWXU);
- mkdir(cacheDir2, S_IRWXU);
- //mkstemp opens the file for safety, but bundlecache_delete needs to reopen the file
- close(mkstemp(cacheFile));
+ int rv = 0;
+ rv += mkdir(cacheDir, S_IRWXU);
+ rv += mkdir(cacheDir2, S_IRWXU);
+ /* Check previous mkdir calls were fine*/
+ LONGS_EQUAL(rv,0);
+
+ //mkstemp opens the file for safety, but bundlecache_delete needs to reopen the file
+ int fd = mkstemp(cacheFile);
+ if(fd>=0){
+ close(fd);
+ }
LONGS_EQUAL(CELIX_SUCCESS, bundleCache_delete(cache));
@@ -94,9 +101,13 @@ TEST(bundle_cache, getArchive) {
char bundle0[] = "bundle_cache_test_directory/bundle0";
char bundle1[] = "bundle_cache_test_directory/bundle1";
- mkdir(cacheDir, S_IRWXU);
- mkdir(bundle0, S_IRWXU);
- mkdir(bundle1, S_IRWXU);
+ int rv = 0;
+ rv += mkdir(cacheDir, S_IRWXU);
+ rv += mkdir(bundle0, S_IRWXU);
+ rv += mkdir(bundle1, S_IRWXU);
+
+ /* Check previous mkdir calls were fine*/
+ LONGS_EQUAL(rv,0);
bundle_archive_pt archive = (bundle_archive_pt) 0x10;
mock().expectOneCall("bundleArchive_recreate")
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/framework/private/test/bundle_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/bundle_test.cpp b/framework/private/test/bundle_test.cpp
index af23dbc..5dfb2be 100644
--- a/framework/private/test/bundle_test.cpp
+++ b/framework/private/test/bundle_test.cpp
@@ -634,7 +634,7 @@ TEST(bundle, revise) {
bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle));
arrayList_create(&bundle->modules);
bundle_archive_pt actual_archive = (bundle_archive_pt) 0x02;
- bundle_revision_pt actual_revision = (bundle_revision_pt) malloc(sizeof(actual_revision));
+ bundle_revision_pt actual_revision = (bundle_revision_pt) malloc(sizeof(*actual_revision));
manifest_pt actual_manifest = (manifest_pt) malloc(sizeof(*actual_manifest));
int actual_id = 666;
const char * actual_module_id = "666.0";
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/log_service/private/src/log.c
----------------------------------------------------------------------
diff --git a/log_service/private/src/log.c b/log_service/private/src/log.c
index a6c3887..5b29318 100644
--- a/log_service/private/src/log.c
+++ b/log_service/private/src/log.c
@@ -252,8 +252,8 @@ celix_status_t log_addLogListener(log_pt logger, log_listener_pt listener) {
celix_status_t log_removeLogListener(log_pt logger, log_listener_pt listener) {
celix_status_t status = CELIX_SUCCESS;
- status = CELIX_DO_IF(status, celixThreadMutex_lock(&logger->deliverLock));
- status = CELIX_DO_IF(status, celixThreadMutex_lock(&logger->listenerLock));
+ status += celixThreadMutex_lock(&logger->deliverLock);
+ status += celixThreadMutex_lock(&logger->listenerLock);
if (status == CELIX_SUCCESS) {
bool last = false;
@@ -264,11 +264,11 @@ celix_status_t log_removeLogListener(log_pt logger, log_listener_pt listener) {
last = true;
}
- status = CELIX_DO_IF(status, celixThreadMutex_unlock(&logger->listenerLock));
- status = CELIX_DO_IF(status, celixThreadMutex_unlock(&logger->deliverLock));
+ status += celixThreadMutex_unlock(&logger->listenerLock);
+ status += celixThreadMutex_unlock(&logger->deliverLock);
if (last) {
- status = CELIX_DO_IF(status, celixThread_join(logger->listenerThread, NULL));
+ status += celixThread_join(logger->listenerThread, NULL);
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/log_service/private/src/log_reader_service_impl.c
----------------------------------------------------------------------
diff --git a/log_service/private/src/log_reader_service_impl.c b/log_service/private/src/log_reader_service_impl.c
index cddb2a8..2a46ea7 100644
--- a/log_service/private/src/log_reader_service_impl.c
+++ b/log_service/private/src/log_reader_service_impl.c
@@ -39,7 +39,7 @@ celix_status_t logReaderService_create(log_pt log, log_reader_data_pt *reader) {
*reader = (log_reader_data_pt) calloc(1, sizeof(**reader));
- if (reader == NULL) {
+ if (*reader == NULL) {
status = CELIX_ENOMEM;
} else {
(*reader)->log = log;
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/log_service/private/src/log_service_impl.c
----------------------------------------------------------------------
diff --git a/log_service/private/src/log_service_impl.c b/log_service/private/src/log_service_impl.c
index ad6313b..c7fa850 100644
--- a/log_service/private/src/log_service_impl.c
+++ b/log_service/private/src/log_service_impl.c
@@ -87,8 +87,10 @@ celix_status_t logService_logSr(log_service_data_pt logger, service_reference_pt
}
}
- logEntry_create(bundleId, symbolicName, reference, level, message, 0, &entry);
- log_addEntry(logger->log, entry);
+ if(status == CELIX_SUCCESS && symbolicName != NULL && message != NULL){
+ status = logEntry_create(bundleId, symbolicName, reference, level, message, 0, &entry);
+ log_addEntry(logger->log, entry);
+ }
- return CELIX_SUCCESS;
+ return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/137fdf5c/log_service/public/src/log_helper.c
----------------------------------------------------------------------
diff --git a/log_service/public/src/log_helper.c b/log_service/public/src/log_helper.c
index 91554a9..12ebe0b 100644
--- a/log_service/public/src/log_helper.c
+++ b/log_service/public/src/log_helper.c
@@ -162,27 +162,25 @@ celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* m
msg[0] = '\0';
bool logged = false;
+ if(loghelper == NULL){
+ return CELIX_ILLEGAL_ARGUMENT;
+ }
+
va_start(listPointer, message);
vsnprintf(msg, 1024, message, listPointer);
- if (loghelper != NULL) {
- pthread_mutex_lock(&loghelper->logListLock);
-
- int i = 0;
-
- for (; i < arrayList_size(loghelper->logServices); i++) {
-
- log_service_pt logService = arrayList_get(loghelper->logServices, i);
+ pthread_mutex_lock(&loghelper->logListLock);
- if (logService != NULL) {
- (logService->log)(logService->logger, level, msg);
- logged = true;
- }
+ int i = 0;
+ for (; i < arrayList_size(loghelper->logServices); i++) {
+ log_service_pt logService = arrayList_get(loghelper->logServices, i);
+ if (logService != NULL) {
+ (logService->log)(logService->logger, level, msg);
+ logged = true;
}
-
- pthread_mutex_unlock(&loghelper->logListLock);
}
+ pthread_mutex_unlock(&loghelper->logListLock);
if (!logged && loghelper->stdOutFallback) {
char *levelStr = NULL;
@@ -206,6 +204,7 @@ celix_status_t logHelper_log(log_helper_pt loghelper, log_level_t level, char* m
printf("%s: %s\n", levelStr, msg);
}
+ va_end(listPointer);
return status;
}