This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch hotfix/service_tracker_guard_condition in repository https://gitbox.apache.org/repos/asf/celix.git
commit 677bf06b39bdcf91ffdac0856b77d784fe37397b Author: PengZheng <[email protected]> AuthorDate: Fri Sep 9 11:15:58 2022 +0800 Fix wrong guard condition in ServiceTracker. --- libs/framework/gtest/src/bundle_context_services_test.cpp | 13 +++++++++++++ libs/framework/src/service_tracker.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/framework/gtest/src/bundle_context_services_test.cpp b/libs/framework/gtest/src/bundle_context_services_test.cpp index 352fc09c..199e214c 100644 --- a/libs/framework/gtest/src/bundle_context_services_test.cpp +++ b/libs/framework/gtest/src/bundle_context_services_test.cpp @@ -762,6 +762,7 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithAlreadyRegistered TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) { int count = 0; + int count2 = 0; auto add = [](void *handle, void *svc, const properties_t *props) { ASSERT_TRUE(svc != nullptr); ASSERT_TRUE(props != nullptr); @@ -786,14 +787,26 @@ TEST_F(CelixBundleContextServicesTests, servicesTrackerTestWithProperties) { ASSERT_TRUE(trackerId >= 0); ASSERT_EQ(1, count); + celix_service_tracking_options_t opts2{}; + opts2.filter.serviceName = "calc"; + opts2.callbackHandle = &count2; + opts2.addWithProperties = nullptr; + opts2.removeWithProperties = remove; + long trackerId2 = celix_bundleContext_trackServicesWithOptions(ctx, &opts2); + ASSERT_TRUE(trackerId2 >= 0); + ASSERT_EQ(0, count2); + long svcId2 = celix_bundleContext_registerService(ctx, (void*)0x200, "calc", nullptr); ASSERT_TRUE(svcId1 >= 0); ASSERT_EQ(2, count); + ASSERT_EQ(0, count2); celix_bundleContext_unregisterService(ctx, svcId1); celix_bundleContext_unregisterService(ctx, svcId2); ASSERT_EQ(0, count); + ASSERT_EQ(-2, count2); + celix_bundleContext_stopTracker(ctx, trackerId2); celix_bundleContext_stopTracker(ctx, trackerId); } diff --git a/libs/framework/src/service_tracker.c b/libs/framework/src/service_tracker.c index c0236b81..e7ed8caf 100644 --- a/libs/framework/src/service_tracker.c +++ b/libs/framework/src/service_tracker.c @@ -593,7 +593,7 @@ static celix_status_t serviceTracker_invokeRemovingService(service_tracker_t *tr if (tracker->remove != NULL) { tracker->remove(handle, tracked->service); } - if (tracker->addWithProperties != NULL) { + if (tracker->removeWithProperties != NULL) { tracker->removeWithProperties(handle, tracked->service, tracked->properties); } if (tracker->removeWithOwner != NULL) {
