This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch hotfix/coverity_fix in repository https://gitbox.apache.org/repos/asf/celix.git
commit 8399e867a8ae158ffc0869c6157808a86a77ca3b Author: PengZheng <[email protected]> AuthorDate: Mon Apr 10 16:57:58 2023 +0800 Fix Coverity 211202 Dereference after null check. --- libs/framework/src/bundle_context.c | 17 ++++------------- libs/framework/src/framework.c | 6 +++--- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/libs/framework/src/bundle_context.c b/libs/framework/src/bundle_context.c index 3e43531d..560868d9 100644 --- a/libs/framework/src/bundle_context.c +++ b/libs/framework/src/bundle_context.c @@ -186,20 +186,11 @@ celix_status_t bundleContext_registerService(bundle_context_pt context, const ch celix_status_t bundleContext_registerServiceFactory(bundle_context_pt context, const char * serviceName, service_factory_pt factory, properties_pt properties, service_registration_pt *service_registration) { - service_registration_pt registration = NULL; - celix_status_t status = CELIX_SUCCESS; - - if (context != NULL && *service_registration == NULL) { - long bndId = celix_bundle_getId(context->bundle); - fw_registerServiceFactory(context->framework, ®istration, bndId, serviceName, factory, properties); - *service_registration = registration; - } else { - status = CELIX_ILLEGAL_ARGUMENT; + if (context == NULL || service_registration == NULL) { + return CELIX_ILLEGAL_ARGUMENT; } - - framework_logIfError(context->framework->logger, status, NULL, "Failed to register service factory"); - - return status; + long bndId = celix_bundle_getId(context->bundle); + return fw_registerServiceFactory(context->framework, service_registration, bndId, serviceName, factory, properties); } celix_status_t bundleContext_getServiceReferences(bundle_context_pt context, const char * serviceName, const char * filter, array_list_pt *service_references) { diff --git a/libs/framework/src/framework.c b/libs/framework/src/framework.c index f98a0989..d4f06f42 100644 --- a/libs/framework/src/framework.c +++ b/libs/framework/src/framework.c @@ -808,7 +808,7 @@ celix_status_t fw_registerService(framework_pt framework, service_registration_p celix_status_t fw_registerServiceFactory(framework_pt framework, service_registration_pt *registration, long bndId, const char* serviceName, service_factory_pt factory, properties_pt properties) { celix_status_t status = CELIX_SUCCESS; char *error = NULL; - if (serviceName == NULL || factory == NULL) { + if (serviceName == NULL || factory == NULL) { status = CELIX_ILLEGAL_ARGUMENT; error = "Service name and factory cannot be null"; } @@ -816,13 +816,13 @@ celix_status_t fw_registerServiceFactory(framework_pt framework, service_registr celix_framework_bundle_entry_t *entry = celix_framework_bundleEntry_getBundleEntryAndIncreaseUseCount(framework, bndId); - status = CELIX_DO_IF(status, serviceRegistry_registerServiceFactory(framework->registry, entry->bnd, serviceName, factory, properties, registration)); + status = CELIX_DO_IF(status, serviceRegistry_registerServiceFactory(framework->registry, entry->bnd, serviceName, factory, properties, registration)); celix_framework_bundleEntry_decreaseUseCount(entry); framework_logIfError(framework->logger, status, error, "Cannot register service factory: %s", serviceName); - return CELIX_SUCCESS; + return status; } celix_status_t fw_getServiceReferences(framework_pt framework, array_list_pt *references, bundle_pt bundle, const char * serviceName, const char * sfilter) {
