Removed potential null-dereference when retrieving hook services
@@ -1674,8 +1674,9 @@ void fw_addServiceListener(framework_pt framework, bundle_pt bundle, celix_servi
celixThreadMutex_unlock(&framework->serviceListenersLock);
//TODO lock listeners hooks?
- serviceRegistry_getListenerHooks(framework->registry, framework->bundle, &listenerHooks);
+ celix_status_t status = serviceRegistry_getListenerHooks(framework->registry, framework->bundle, &listenerHooks);
+ if (status == CELIX_SUCCESS) {
struct listener_hook_info info;
bundle_getContext(bundle, &context);
@@ -1689,18 +1690,23 @@ void fw_addServiceListener(framework_pt framework, bundle_pt bundle, celix_servi
array_list_pt infos = NULL;
bool ungetResult = false;
- fw_getService(framework, framework->bundle, ref, (const void **) &hook);
+ status = fw_getService(framework, framework->bundle, ref, (const void **) &hook);
+ if (status == CELIX_SUCCESS && hook != NULL) {
arrayList_create(&infos);
arrayList_add(infos, &info);
hook->added(hook->handle, infos);
serviceRegistry_ungetService(framework->registry, framework->bundle, ref, &ungetResult);
serviceRegistry_ungetServiceReference(framework->registry, framework->bundle, ref);
arrayList_destroy(infos);
+ } else {
+ fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, "Could not retrieve hook service.");
+ }
}
arrayList_destroy(listenerHooks);
}
+}
void fw_removeServiceListener(framework_pt framework, bundle_pt bundle, celix_service_listener_t *listener) {
celix_fw_service_listener_entry_t *match = NULL;
